Skip to content

Commit 7c0a2c8

Browse files
committed
update on new api create form control
1 parent 155ed02 commit 7c0a2c8

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

src/components/Menu/MenuLinks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ export const apiLinks: Pages = [
159159
pathname: "/docs/usefieldarray",
160160
name: "useFieldArray",
161161
},
162+
{
163+
pathname: "/docs/createFormControl",
164+
name: "createFormControl",
165+
},
162166
]
163167

164168
export const tsLinks: Pages = [
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: createFormControl
3+
description: Create form state and ready to be subscribed
4+
sidebar: apiLinks
5+
---
6+
7+
This function create the entire form state subscription and allow you to subscribe update with or without react component.
8+
9+
### Props
10+
11+
---
12+
13+
This following table applied to `FormProvider`, `useFormContext` accepts no argument.
14+
15+
| Name | Type | Description |
16+
| ---------- | --------------------------- | ---------------------------------------------- |
17+
| `...props` | <TypeText>Object</TypeText> | `UseFormProps` |
18+
19+
**Examples:**
20+
21+
---
22+
23+
<TabGroup buttonLabels={["Setup", "Subscribe"]}>
24+
25+
```javascript
26+
const { formControl, control } = createFormControl({
27+
mode: 'onChange',
28+
defaultValues: {
29+
firstName: 'Bill'
30+
}
31+
}})
32+
33+
function App() {
34+
const { register } = useForm({
35+
formControl,
36+
})
37+
38+
return (
39+
<form>
40+
<FormState />
41+
<Controller />
42+
</form>
43+
);
44+
}
45+
46+
function FormState() {
47+
useFormState({
48+
control // no longer need context api
49+
})
50+
}
51+
52+
function Controller() {
53+
useFormState({
54+
control // no longer need context api
55+
})
56+
}
57+
```
58+
59+
```javascript
60+
const { formControl } = createFormControl(props)
61+
62+
formControl.subscribe({
63+
formState: { isDirty: true },
64+
callback: (formState) => {
65+
if (formState.isDirty) {
66+
// do something here
67+
}
68+
}
69+
})
70+
71+
function App() {
72+
const { register } = useForm({
73+
formControl,
74+
})
75+
76+
return <form />
77+
}
78+
```
79+
</TabGroup>

0 commit comments

Comments
 (0)