www: Various documentation improvements (#1635)

Co-authored-by: Reed von Redwitz <reed+github@vonredwitz.com>
This commit is contained in:
Marvin Hagemeister
2023-08-16 16:24:53 +02:00
committed by GitHub
co-authored by Reed von Redwitz
parent 794c8ac10c
commit b2362da281
14 changed files with 275 additions and 137 deletions
+20
View File
@@ -165,3 +165,23 @@ export default async function MyPage(req: Request, ctx: RouteContext) {
return <p>foo is: {value}</p>;
}
```
### Define helper
To make it a little quicker to write async routes, Fresh ships with a
`defineRoute` helper which automatically infers the correct types for the
function arguments.
```tsx
import { defineRoute } from "$fresh/server.ts";
export default defineRoute(async (req, ctx) => {
const data = await loadData();
return (
<div class="page">
<h1>Hello {data.name}</h1>
</div>
);
});
```