Skip to content

Commit 58de8fd

Browse files
committed
update create form control api
1 parent 4b1b80f commit 58de8fd

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

src/components/ApiGallery.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,9 @@
9696
display: inline-block;
9797
margin-right: 20px;
9898
}
99+
100+
p.beta {
101+
margin-bottom: -1rem;
102+
font-size: 0.7rem;
103+
color: var(--color-light-grey)
104+
}

src/components/ApiGallery.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,23 @@ export default function ApiGallery() {
160160
</Link>
161161
</div>
162162
</li>
163+
<li>
164+
<div>
165+
<h3>
166+
<code>{`</>`}</code>createFormControl
167+
</h3>
168+
<p className={styles.beta}>BETA @v7.55.0-next.3</p>
169+
<p>
170+
Create form control object and subscribe form state outside of React component, access methods without context.
171+
</p>
172+
<Link
173+
href="/docs/createFormControl"
174+
aria-label="read more about usefieldarray"
175+
>
176+
Read More ▸
177+
</Link>
178+
</div>
179+
</li>
163180
</ul>
164181

165182
<div className={styles.versionControl}>

src/content/docs/createFormControl.mdx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,45 @@ description: Create form state and ready to be subscribed (BETA)
44
sidebar: apiLinks
55
---
66

7-
This function create the entire form state subscription and allow you to subscribe update with or without react component.
7+
This function create the entire form state subscription and allow you to subscribe update with or without react component. You can use this function without the need of React Context api.
88

99
### Props
1010

1111
---
1212

13-
This following table applied to `FormProvider`, `useFormContext` accepts no argument.
14-
1513
| Name | Type | Description |
1614
| ---------- | --------------------------- | -------------- |
1715
| `...props` | <TypeText>Object</TypeText> | `UseFormProps` |
1816

17+
18+
### Returns
19+
20+
---
21+
22+
| Name | Type | Description |
23+
| ---------- | --------------------------- | -------------- |
24+
| `formControl` | <TypeText>Object</TypeText> | control object for `useForm` hook |
25+
| `control` | <TypeText>Object</TypeText> | control object for `useController`, `useFormState`, `useWatch` |
26+
| `...returns` | <TypeText>Functions</TypeText> | `useForm` return methods |
27+
1928
<Admonition type="important" title="Notes">
20-
- This function is published at **v7.55.0-next.1** - This function is
29+
- This function is published at **v7.55.0-next.3** - This function is
2130
completely optional, you can consider to use this instead of `useFormContext`
2231
API. - You may find it useful if you would like to subscribe formsState by
2332
skipping react re-render.
2433
</Admonition>
2534

35+
<Admonition type="important" title="Rules">
36+
- You should either use this API or context API
37+
```tsx
38+
const props = createFormControl()
39+
40+
<FormProvider {...props} /> // ❌ You don't need provider
41+
42+
<input {...props.register('name')} /> // ✅ Direct use method from createFormControl
43+
```
44+
</Admonition>
45+
2646
**Examples:**
2747

2848
---

0 commit comments

Comments
 (0)