Skip to content

Commit

Permalink
docs: corrected example (#2717)
Browse files Browse the repository at this point in the history
* docs: made store consistent with examples in "Selecting multiple state slices"

* docs: responded to review comments

* Update readme.md

* run pretiter

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
Co-authored-by: daishi <daishi@axlight.com>
  • Loading branch information
3 people committed Sep 2, 2024
1 parent 9e8b7a5 commit 4ec7077
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ import { create } from 'zustand'
import { useShallow } from 'zustand/react/shallow'

const useBearStore = create((set) => ({
bears: 0,
increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
removeAllBears: () => set({ bears: 0 }),
nuts: 0,
honey: 0,
treats: {},
// ...
}))

// Object pick, re-renders the component when either state.nuts or state.honey change
Expand All @@ -110,7 +111,7 @@ const [nuts, honey] = useBearStore(
const treats = useBearStore(useShallow((state) => Object.keys(state.treats)))
```

For more control over re-rendering, you may provide any custom equality function.
For more control over re-rendering, you may provide any custom equality function (this example requires the use of [`createWithEqualityFn`](./docs/migrations/migrating-to-v5.md#using-custom-equality-functions-such-as-shallow)).

```jsx
const treats = useBearStore(
Expand Down

0 comments on commit 4ec7077

Please sign in to comment.