Skip to content

Commit f8aff3e

Browse files
committed
docs
1 parent df5e07d commit f8aff3e

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

apps/docs/src/server/docs/04-helpers.md

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,57 @@ title: Helpers
33
description: ovr route helpers.
44
---
55

6-
ovr provides helpers to encapsulate a route, allowing you to easily create a route in a separate module from `App`. Helpers are the best way to create pages and API endpoints for an ovr application.
6+
ovr provides helpers to encapsulate a route, allowing you to easily create a route in a separate module from `App`. Helpers are the best way to create pages, API endpoints, links, and forms in an ovr application.
77

88
## Get
99

10-
`Get` creates a [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/GET) route and corresponding `Anchor`, `Button`, and `Form` components for it. This ensures if you change the route's pattern, you don't need to update all of the links to it throughout your application.
10+
`Get` creates a [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/GET) route and corresponding `Anchor`, `Button`, and `Form` components for it. This ensures if you change the route's pattern, you don't need to update all of the links to it throughout your application. Anytime you need to generate a link to a page use the `Anchor` component from the `Get` helper.
1111

1212
```tsx
1313
import { Get } from "ovr";
1414

1515
const page = new Get("/", () => {
16-
return <p>hello world</p>;
17-
});
16+
return (
17+
<main>
18+
<p>Hello world!</p>
1819

19-
// <a> tag with preset `href` attribute
20-
<page.Anchor>Home</page.Anchor>;
20+
{/* <a> tag with preset `href` attribute */}
21+
<page.Anchor>Home</page.Anchor>
2122

22-
// <button> component with preset `formaction` and `formmethod` attributes
23-
<page.Button>Submit</page.Button>
23+
{/* <button> component with preset `formaction` and `formmethod` attributes */}
24+
<page.Button>Submit</page.Button>
2425

25-
// <form> tag with preset `action` attribute
26-
<page.Form>...</page.Form>;
26+
{/* <form> tag with preset `action` attribute */}
27+
<page.Form>...</page.Form>
28+
</main>
29+
);
30+
});
2731
```
2832

2933
## Post
3034

31-
There is also a `Post` helper that will create a [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/POST) handler and corresponding `Form` and `Button` elements.
35+
There is also a `Post` helper that will create a [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/POST) handler and corresponding `Form` and `Button` elements. Anytime you need to handle a form submission, use the generated `Form` component from the `Post` helper.
3236

3337
```tsx
34-
import { Post } from "ovr";
38+
import { Get, Post } from "ovr";
3539

36-
const login = new Post((c) => {
40+
const login = new Post(async (c) => {
3741
const data = await c.req.formData();
38-
3942
// ...
40-
4143
c.redirect("/", 303);
42-
})
43-
44-
// <form> with preset `method` and `action` attributes
45-
<login.Form>...</login.Form>;
44+
});
4645

47-
// <button> component with preset `formaction` and `formmethod` attributes
48-
<login.Button>Submit</login.Button>
46+
const page = new Get("/", () => {
47+
return (
48+
<main>
49+
{/* <form> with preset `method` and `action` attributes */}
50+
<login.Form>...</login.Form>
51+
52+
{/* <button> component with preset `formaction` and `formmethod` attributes */}
53+
<login.Button>Submit</login.Button>
54+
</main>
55+
);
56+
});
4957
```
5058

5159
For `Post`, ovr will automatically create a unique pattern for the route based on a hash of the middleware provided.

0 commit comments

Comments
 (0)