www: cleanup miscellaneous doc items (#1419)
This commit is contained in:
@@ -35,7 +35,7 @@ full files are available at the bottom for reference.
|
||||
`POST` (create) is used to create a resource.
|
||||
|
||||
```tsx
|
||||
// /routes/api/index.ts
|
||||
// routes/api/index.ts
|
||||
export const handler: Handlers<User | null> = {
|
||||
async POST(req, _ctx) {
|
||||
const user = await req.json() as User;
|
||||
@@ -72,7 +72,7 @@ You should receive the same thing back:
|
||||
method. You can use `GET` to fetch database content, markdown, or static files.
|
||||
|
||||
```tsx
|
||||
// /routes/api/[id].ts
|
||||
// routes/api/[id].ts
|
||||
export const handler: Handlers<User | null> = {
|
||||
async GET(_req, ctx) {
|
||||
const id = ctx.params.id;
|
||||
@@ -103,7 +103,7 @@ The short version of it: `PUT` requires the entire object to be submitted, while
|
||||
An example of an update endpoint using `PUT`:
|
||||
|
||||
```tsx
|
||||
// /routes/api/[id].ts
|
||||
// routes/api/[id].ts
|
||||
export const handler: Handlers<User | null> = {
|
||||
async PUT(req, ctx) {
|
||||
const id = ctx.params.id;
|
||||
@@ -153,7 +153,7 @@ No need to send in the id in this case.
|
||||
`DELETE` (delete) is used to delete a resource.
|
||||
|
||||
```tsx
|
||||
// /routes/api/[id].ts
|
||||
// routes/api/[id].ts
|
||||
export const handler: Handlers<User | null> = {
|
||||
async DELETE(_req, ctx) {
|
||||
const id = ctx.params.id;
|
||||
|
||||
@@ -15,6 +15,7 @@ The following file uses
|
||||
handle the three cases. It's assumed this file is called `[slug].tsx`:
|
||||
|
||||
```ts
|
||||
// routes/[slug].tsx
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
import { extract } from "$std/front_matter/yaml.ts";
|
||||
import { CSS, render } from "$gfm";
|
||||
|
||||
@@ -12,6 +12,7 @@ All of this content is lifted from this great
|
||||
Imagine we have `Counter.tsx` like this:
|
||||
|
||||
```ts
|
||||
// islands/Counter.tsx
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { Button } from "../components/Button.tsx";
|
||||
|
||||
@@ -49,6 +50,7 @@ here, yet.
|
||||
But we can switch things up by looking at a `SynchronizedSlider.tsx` like this:
|
||||
|
||||
```ts
|
||||
// islands/SynchronizedSlider.tsx
|
||||
import { Signal } from "@preact/signals";
|
||||
|
||||
interface SliderProps {
|
||||
@@ -74,6 +76,7 @@ export default function SynchronizedSlider(props: SliderProps) {
|
||||
Now if we were to do the following...
|
||||
|
||||
```ts
|
||||
// routes/index.tsx
|
||||
export default function Home() {
|
||||
const sliderSignal = useSignal(50);
|
||||
return (
|
||||
@@ -93,17 +96,15 @@ they would all use the same value.
|
||||
We can also create a `signal` in a utility file and export it for consumption
|
||||
across multiple places.
|
||||
|
||||
`./utils/cart.ts`
|
||||
|
||||
```ts
|
||||
// utils/cart.ts
|
||||
import { signal } from "@preact/signals";
|
||||
|
||||
export const cart = signal<string[]>([]);
|
||||
```
|
||||
|
||||
`./islands/AddToCart.tsx`
|
||||
|
||||
```ts
|
||||
// islands/AddToCart.tsx
|
||||
import { Button } from "../components/Button.tsx";
|
||||
import { cart } from "../utils/cart.ts";
|
||||
|
||||
@@ -125,9 +126,8 @@ export default function AddToCart(props: AddToCartProps) {
|
||||
}
|
||||
```
|
||||
|
||||
`./islands/Cart.tsx`
|
||||
|
||||
```ts
|
||||
// islands/Cart.tsx
|
||||
import { Button } from "../components/Button.tsx";
|
||||
import { cart } from "../utils/cart.ts";
|
||||
import * as icons from "../components/Icons.tsx";
|
||||
|
||||
Reference in New Issue
Block a user