diff --git a/src/content/docs/useform.mdx b/src/content/docs/useform.mdx index 5ad2aff52..7999930bf 100644 --- a/src/content/docs/useform.mdx +++ b/src/content/docs/useform.mdx @@ -494,10 +494,12 @@ const App = () => { }) return ( -
{ - // handle inputs - console.log(data); - })}> + { + // handle inputs + console.log(data) + })} +> @@ -507,27 +509,31 @@ 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({ - resolver: joiResolver(schema) - }); + const { + register, + handleSubmit, + formState: { errors }, + } = useForm({ + resolver: joiResolver(schema), + }) const onSubmit = (data: IFormInput) => { - console.log(data); - }; + console.log(data) + } return ( @@ -535,7 +541,7 @@ const App = () => { - ); + ) } ``` diff --git a/src/content/docs/useform/handlesubmit.mdx b/src/content/docs/useform/handlesubmit.mdx index 773641adc..4246c0c81 100644 --- a/src/content/docs/useform/handlesubmit.mdx +++ b/src/content/docs/useform/handlesubmit.mdx @@ -66,7 +66,8 @@ type FormValues = { export default function App() { const { register, handleSubmit } = useForm() const onSubmit: SubmitHandler = (data) => console.log(data) - const onError: SubmitErrorHandler = (errors) => console.log(errors) + const onError: SubmitErrorHandler = (errors) => + console.log(errors) return (
diff --git a/src/content/docs/useform/subscribe.mdx b/src/content/docs/useform/subscribe.mdx index 86d9fc075..e9c467574 100644 --- a/src/content/docs/useform/subscribe.mdx +++ b/src/content/docs/useform/subscribe.mdx @@ -12,19 +12,23 @@ Subscribe to [`formState`](/docs/useform/formState) changes and value updates. Y --- -| Name | Type | Description | Example | -| --------- | --------------------------------------------- | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| name | undefined | Subscribe to the entire form | `subscribe()` | -| | string[] | Subscribe on multiple fields by **name**. | `subscribe({ name: ['firstName', 'lastName'] })` | -| formState | `Partial` | Pick which [`formState`](/docs/useform/formState) to be subscribed. | | -| callback | `Function` | The callback function for the subscription. | { \n console.log(values) \n } \n})`}/> | -| exact | boolean | This prop will enable an exact match for input name subscriptions. | `subscribe({ name: 'target', exact: true })` | +| Name | Type | Description | Example | +| --------- | --------------------------------------------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| name | undefined | Subscribe to the entire form | `subscribe()` | +| | string[] | Subscribe on multiple fields by **name**. | `subscribe({ name: ['firstName', 'lastName'] })` | +| formState | `Partial` | Pick which [`formState`](/docs/useform/formstate) to be subscribed. | | +| callback | `Function` | The callback function for the subscription. | { \n console.log(values) \n } \n})`}/> | +| exact | boolean | This prop will enable an exact match for input name subscriptions. | `subscribe({ name: 'target', exact: true })` |
  • -

    This function is intended for subscribing to changes only; dispatching state updates or triggering re-renders is not allowed. eg `setValue` or `reset`

    +

    + This function is intended for subscribing to changes only; dispatching + state updates or triggering re-renders is not allowed. eg `setValue` or + `reset` +

  • @@ -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();

    AltStyle によって変換されたページ (->オリジナル) /