Skip to content

Commit

Permalink
Added note about formstate section
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachSelindh authored and slax57 committed Sep 28, 2023
1 parent be29a1d commit b8baede
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docs/useInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,20 @@ const PersonEdit = () => (

**Tip**: Remember to use react-admin's `<InputHelperText>` component in custom inputs to properly translate and render messages and errors coming from `useInput()`.

**Reminder:** [react-hook-form's `formState` is wrapped with a Proxy](https://react-hook-form.com/docs/useformstate/#rules) to improve render performance and skip extra computation if specific state is not subscribed. So, make sure you deconstruct or read the `formState` before render in order to enable the subscription.
## Important note about formState

[react-hook-form's `formState` is wrapped with a Proxy](https://react-hook-form.com/docs/useformstate/#rules) to improve render performance and skip extra computation if specific state is not subscribed. So, make sure you deconstruct or read the `formState` before render in order to enable the subscription.

```js
const { isDirty } = useFormState(); //
const formState = useFormState(); // ❌ should deconstruct the formState
```

This pattern should be followed when writing a custom input with `useInput()`.

```jsx
const { formState: { isSubmitted }} = useInput(props); //

const { formState } = useInput(props);
const submitted = formState.isSubmitted; //
```

0 comments on commit b8baede

Please sign in to comment.