mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
Update Transient in recipes to match Readme (#1764)
* Update Transient in recipes to match Readme https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes * Update docs/recipes/recipes.mdx Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com> * update to useScratchStore --------- Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
This commit is contained in:
parent
da450384a9
commit
513b22283e
@ -201,15 +201,14 @@ This can make a [drastic](https://codesandbox.io/s/peaceful-johnson-txtws)
|
||||
performance impact, when you are allowed to mutate the view directly.
|
||||
|
||||
```jsx
|
||||
const useStore = create(set => ({ scratches: 0, ... }))
|
||||
const useScratchStore = create(set => ({ scratches: 0, ... }))
|
||||
|
||||
function Component() {
|
||||
// Fetch initial state
|
||||
const scratchRef = useRef(useStore.getState().scratches)
|
||||
const scratchRef = useRef(useScratchStore.getState().scratches)
|
||||
// Connect to the store on mount, disconnect on unmount, catch state-changes in a reference
|
||||
useEffect(() => useStore.subscribe(
|
||||
scratches => (scratchRef.current = scratches),
|
||||
state => state.scratches
|
||||
useEffect(() => useScratchStore.subscribe(
|
||||
(state) => (scratchRef.current = state.scratches)
|
||||
), [])
|
||||
// ...
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user