Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: correct typo issue for link formstate and formState type example #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions src/content/docs/useform.mdx
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,12 @@ const App = () => {
})

return (
<form onSubmit={handleSubmit((data) => {
// handle inputs
console.log(data);
})}>
<form
onSubmit={handleSubmit((data) => {
// handle inputs
console.log(data)
})}
>
<input {...register("name")} />
<input {...register("age", { valueAsNumber: true })} type="number" />
<input type="submit" />
Expand All @@ -507,35 +509,39 @@ const App = () => {
```

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

interface IFormInput {
name: string;
age: number;
name: string
age: number
}

const schema = Joi.object({
name: Joi.string().required(),
age: Joi.number().required()
});
age: Joi.number().required(),
})

const App = () => {
const { register, handleSubmit, formState: { errors } } = useForm<IFormInput>({
resolver: joiResolver(schema)
});
const {
register,
handleSubmit,
formState: { errors },
} = useForm<IFormInput>({
resolver: joiResolver(schema),
})
const onSubmit = (data: IFormInput) => {
console.log(data);
};
console.log(data)
}

return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register("name")} />
<input type="number" {...register("age")} />
<input type="submit" />
</form>
);
)
}
```

Expand Down
3 changes: 2 additions & 1 deletion src/content/docs/useform/handlesubmit.mdx
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ type FormValues = {
export default function App() {
const { register, handleSubmit } = useForm<FormValues>()
const onSubmit: SubmitHandler<FormValues> = (data) => console.log(data)
const onError: SubmitErrorHandler<FormValues> = (errors) => console.log(errors)
const onError: SubmitErrorHandler<FormValues> = (errors) =>
console.log(errors)

return (
<form onSubmit={handleSubmit(onSubmit, onError)}>
Expand Down
28 changes: 16 additions & 12 deletions src/content/docs/useform/subscribe.mdx
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ Subscribe to [`formState`](/docs/useform/formState) changes and value updates. Y

---

| Name | Type | Description | Example |
| --------- | --------------------------------------------- | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name | <TypeText>undefined</TypeText> | Subscribe to the entire form | `subscribe()` |
| | <TypeText>string[]</TypeText> | Subscribe on multiple fields by **name**. | `subscribe({ name: ['firstName', 'lastName'] })` |
| 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})`}/> |
| 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})`}/> |
| exact | <TypeText>boolean</TypeText> | This prop will enable an exact match for input name subscriptions. | `subscribe({ name: 'target', exact: true })` |
| Name | Type | Description | Example |
| --------- | --------------------------------------------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name | <TypeText>undefined</TypeText> | Subscribe to the entire form | `subscribe()` |
| | <TypeText>string[]</TypeText> | Subscribe on multiple fields by **name**. | `subscribe({ name: ['firstName', 'lastName'] })` |
| 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})`}/> |
| 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})`}/> |
| exact | <TypeText>boolean</TypeText> | This prop will enable an exact match for input name subscriptions. | `subscribe({ name: 'target', exact: true })` |

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

<ul>
<li>
<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>
<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>
</li>
<li>
<p>
Expand Down Expand Up @@ -64,14 +68,14 @@ export default function App() {
// make sure to unsubscribe;
const callback = subscribe({
formState: {
values: true
values: true,
},
callback: ({ values }) => {
console.log(values);
}
console.log(values)
},
})

return () => callback();
return () => callback()

// You can also just return the subscribe
// return subscribe();
Expand Down

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /