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:
Mark Rozovsky 2022-08-12 01:37:18 +03:00 committed by GitHub
parent 2122a0c5e7
commit bde75bae52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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>

View File

@ -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