Skip to content

Commit eb75a10

Browse files
fix: correct typo issue for link formstate and formState type example (#1162)
* fix: fix typo issue in link for formState * chore: format code with pnpm run format * fix: correct formState type example * Revert "chore: format code with pnpm run format" This reverts commit 798b9c5. * chore: format code with 'pnpm run format --write' without 'src/content/ts.mdx' file
1 parent 35291ad commit eb75a10

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

src/content/docs/useform.mdx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,12 @@ const App = () => {
494494
})
495495

496496
return (
497-
<form onSubmit={handleSubmit((data) => {
498-
// handle inputs
499-
console.log(data);
500-
})}>
497+
<form
498+
onSubmit={handleSubmit((data) => {
499+
// handle inputs
500+
console.log(data)
501+
})}
502+
>
501503
<input {...register("name")} />
502504
<input {...register("age", { valueAsNumber: true })} type="number" />
503505
<input type="submit" />
@@ -507,35 +509,39 @@ const App = () => {
507509
```
508510

509511
```tsx copy sandbox="https://codesandbox.io/s/react-hook-form-joiresolver-v6-ts-forked-5pseh"
510-
import { useForm } from "react-hook-form";
511-
import { joiResolver } from "@hookform/resolvers/joi";
512-
import Joi from "joi";
512+
import { useForm } from "react-hook-form"
513+
import { joiResolver } from "@hookform/resolvers/joi"
514+
import Joi from "joi"
513515

514516
interface IFormInput {
515-
name: string;
516-
age: number;
517+
name: string
518+
age: number
517519
}
518520

519521
const schema = Joi.object({
520522
name: Joi.string().required(),
521-
age: Joi.number().required()
522-
});
523+
age: Joi.number().required(),
524+
})
523525

524526
const App = () => {
525-
const { register, handleSubmit, formState: { errors } } = useForm<IFormInput>({
526-
resolver: joiResolver(schema)
527-
});
527+
const {
528+
register,
529+
handleSubmit,
530+
formState: { errors },
531+
} = useForm<IFormInput>({
532+
resolver: joiResolver(schema),
533+
})
528534
const onSubmit = (data: IFormInput) => {
529-
console.log(data);
530-
};
535+
console.log(data)
536+
}
531537

532538
return (
533539
<form onSubmit={handleSubmit(onSubmit)}>
534540
<input {...register("name")} />
535541
<input type="number" {...register("age")} />
536542
<input type="submit" />
537543
</form>
538-
);
544+
)
539545
}
540546
```
541547

src/content/docs/useform/handlesubmit.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ type FormValues = {
6666
export default function App() {
6767
const { register, handleSubmit } = useForm<FormValues>()
6868
const onSubmit: SubmitHandler<FormValues> = (data) => console.log(data)
69-
const onError: SubmitErrorHandler<FormValues> = (errors) => console.log(errors)
69+
const onError: SubmitErrorHandler<FormValues> = (errors) =>
70+
console.log(errors)
7071

7172
return (
7273
<form onSubmit={handleSubmit(onSubmit, onError)}>

src/content/docs/useform/subscribe.mdx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@ Subscribe to [`formState`](/docs/useform/formState) changes and value updates. Y
1212

1313
---
1414

15-
| Name | Type | Description | Example |
16-
| --------- | --------------------------------------------- | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17-
| name | <TypeText>undefined</TypeText> | Subscribe to the entire form | `subscribe()` |
18-
| | <TypeText>string[]</TypeText> | Subscribe on multiple fields by **name**. | `subscribe({ name: ['firstName', 'lastName'] })` |
19-
| formState | <TypeText>`Partial<ReadFormState>`</TypeText> | Pick which [`formState`](/docs/useform/formState) to be subscribed. | <CodeArea withOutCopy rawData={`subscribe({ \n formState: { \n values: true, \n isDirty: true, \n dirtyFields: true, \n touchedFields: true, \n isValid: true, \n errors: true, \n defaultValues: true, \n isSubmitted: true \n } \n})`}/> |
20-
| callback | <TypeText>`Function`</TypeText> | The callback function for the subscription. | <CodeArea withOutCopy rawData={`subscribe({ \n formState: { \n values: true \n }, \n callback: ({ values }) => { \n console.log(values) \n } \n})`}/> |
21-
| exact | <TypeText>boolean</TypeText> | This prop will enable an exact match for input name subscriptions. | `subscribe({ name: 'target', exact: true })` |
15+
| Name | Type | Description | Example |
16+
| --------- | --------------------------------------------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
17+
| name | <TypeText>undefined</TypeText> | Subscribe to the entire form | `subscribe()` |
18+
| | <TypeText>string[]</TypeText> | Subscribe on multiple fields by **name**. | `subscribe({ name: ['firstName', 'lastName'] })` |
19+
| formState | <TypeText>`Partial<ReadFormState>`</TypeText> | Pick which [`formState`](/docs/useform/formstate) to be subscribed. | <CodeArea withOutCopy rawData={`subscribe({ \n formState: { \n values: true, \n isDirty: true, \n dirtyFields: true, \n touchedFields: true, \n isValid: true, \n errors: true, \n validatingFields: true, \n isValidating: true \n } \n})`}/> |
20+
| callback | <TypeText>`Function`</TypeText> | The callback function for the subscription. | <CodeArea withOutCopy rawData={`subscribe({ \n formState: { \n values: true \n }, \n callback: ({ values }) => { \n console.log(values) \n } \n})`}/> |
21+
| exact | <TypeText>boolean</TypeText> | This prop will enable an exact match for input name subscriptions. | `subscribe({ name: 'target', exact: true })` |
2222

2323
<Admonition type="important" title="Notes">
2424

2525
<ul>
2626
<li>
27-
<p>This function is intended for subscribing to changes only; dispatching state updates or triggering re-renders is not allowed. eg `setValue` or `reset`</p>
27+
<p>
28+
This function is intended for subscribing to changes only; dispatching
29+
state updates or triggering re-renders is not allowed. eg `setValue` or
30+
`reset`
31+
</p>
2832
</li>
2933
<li>
3034
<p>
@@ -64,14 +68,14 @@ export default function App() {
6468
// make sure to unsubscribe;
6569
const callback = subscribe({
6670
formState: {
67-
values: true
71+
values: true,
6872
},
6973
callback: ({ values }) => {
70-
console.log(values);
71-
}
74+
console.log(values)
75+
},
7276
})
7377

74-
return () => callback();
78+
return () => callback()
7579

7680
// You can also just return the subscribe
7781
// return subscribe();

0 commit comments

Comments
 (0)