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:
Tim Arney 2023-04-24 10:29:29 -04:00 committed by GitHub
parent da450384a9
commit 513b22283e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
), [])
// ...
}