Skip to content

Commit

Permalink
docs: risks of omitting useStore selector (#1126)
Browse files Browse the repository at this point in the history
Co-authored-by: Harry Whorlow <[email protected]>
  • Loading branch information
harry-whorlow and Harry Whorlow authored Feb 5, 2025
1 parent e53573f commit 2bd0696
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/framework/react/guides/basic-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ const firstName = useStore(form.store, (state) => state.values.firstName)
/>
```

It is important to remember that while the `useStore` hook's `selector` prop is optional, it is strongly recommended to provide one, as omitting it will result in unnecessary re-renders.

```tsx
// Correct use
const firstName = useStore(form.store, (state) => state.values.firstName)
const errors = useStore(form.store, (state) => state.errorMap)
// Incorrect use
const store = useStore(form.store)
```

Note: The usage of the `useField` hook to achieve reactivity is discouraged since it is designed to be used thoughtfully within the `form.Field` component. You might want to use `useStore(form.store)` instead.

## Listeners
Expand Down

0 comments on commit 2bd0696

Please sign in to comment.