mirror of
https://github.com/pmndrs/zustand.git
synced 2025-12-08 19:45:52 +00:00
docs: Made minor fix for the recipes (#1188)
* Update recipes.mdx * add warnings * fix prettier Co-authored-by: daishi <daishi@axlight.com>
This commit is contained in:
parent
2122a0c5e7
commit
bde75bae52
@ -4,6 +4,8 @@ description: How to use Zustand
|
||||
nav: 0
|
||||
---
|
||||
|
||||
:warning: This doc is still under construction. https://github.com/pmndrs/zustand/discussions/1033
|
||||
|
||||
<p align="center">
|
||||
<img width="500" src="https://docs.pmnd.rs/zustand-resources/bear.png" />
|
||||
</p>
|
||||
|
||||
@ -4,6 +4,8 @@ description: How to do all you need with Zustand
|
||||
nav: 1
|
||||
---
|
||||
|
||||
:warning: This doc is still under construction. https://github.com/pmndrs/zustand/discussions/1033
|
||||
|
||||
## Fetching everything
|
||||
|
||||
You can, but bear in mind that it will cause the component to update on every state change!
|
||||
@ -121,8 +123,16 @@ const useStore = create((set, get) => ({
|
||||
|
||||
Sometimes you need to access state in a non-reactive way, or act upon the store. For these cases the resulting hook has utility functions attached to its prototype.
|
||||
|
||||
If you need to subscribe with selector, subscribeWithSelector middleware will help.
|
||||
With this middleware subscribe accepts an additional signature:
|
||||
|
||||
```jsx
|
||||
const useStore = create(() => ({ paw: true, snout: true, fur: true }))
|
||||
subscribe(selector, callback, options?: { equalityFn, fireImmediately }): Unsubscribe
|
||||
```
|
||||
|
||||
```jsx
|
||||
import { subscribeWithSelector } from 'zustand/middleware'
|
||||
const useStore = create(subscribeWithSelector(() => ({ paw: true, snout: true, fur: true })))
|
||||
|
||||
// Getting non-reactive fresh state
|
||||
const paw = useStore.getState().paw
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user