Skip to content

Commit 2bd0696

Browse files
harry-whorlowHarry Whorlow
andauthored
docs: risks of omitting useStore selector (#1126)
Co-authored-by: Harry Whorlow <[email protected]>
1 parent e53573f commit 2bd0696

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docs/framework/react/guides/basic-concepts.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ const firstName = useStore(form.store, (state) => state.values.firstName)
204204
/>
205205
```
206206

207+
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.
208+
209+
```tsx
210+
// Correct use
211+
const firstName = useStore(form.store, (state) => state.values.firstName)
212+
const errors = useStore(form.store, (state) => state.errorMap)
213+
// Incorrect use
214+
const store = useStore(form.store)
215+
```
216+
207217
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.
208218

209219
## Listeners

0 commit comments

Comments
 (0)