You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/src/server/docs/04-helpers.md
+29-21Lines changed: 29 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,49 +3,57 @@ title: Helpers
3
3
description: ovr route helpers.
4
4
---
5
5
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.
7
7
8
8
## Get
9
9
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.
11
11
12
12
```tsx
13
13
import { Get } from"ovr";
14
14
15
15
const page =newGet("/", () => {
16
-
return <p>hello world</p>;
17
-
});
16
+
return (
17
+
<main>
18
+
<p>Hello world!</p>
18
19
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>
21
22
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>
24
25
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
+
});
27
31
```
28
32
29
33
## Post
30
34
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.
32
36
33
37
```tsx
34
-
import { Post } from"ovr";
38
+
import { Get, Post } from"ovr";
35
39
36
-
const login =newPost((c) => {
40
+
const login =newPost(async(c) => {
37
41
const data =awaitc.req.formData();
38
-
39
42
// ...
40
-
41
43
c.redirect("/", 303);
42
-
})
43
-
44
-
// <form> with preset `method` and `action` attributes
45
-
<login.Form>...</login.Form>;
44
+
});
46
45
47
-
// <button> component with preset `formaction` and `formmethod` attributes
48
-
<login.Button>Submit</login.Button>
46
+
const page =newGet("/", () => {
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
+
});
49
57
```
50
58
51
59
For `Post`, ovr will automatically create a unique pattern for the route based on a hash of the middleware provided.
0 commit comments