Skip to content

Selectors vs destructuring #1045

Closed Answered by dai-shi
MichielDeMey asked this question in Q&A
Jun 28, 2022 · 2 comments · 4 replies
Discussion options

You must be logged in to vote

Hi, it's very different if you have isolated anotherCount property in your store.

This 👇 will trigger re-render if anotherCount changes.

const { count } = useStore()

This 👇 will not trigger re-render if anotherCount changes.

const count = useStore(state => state.count)

Maybe the documentation can be improved to help future adopters with best practices?

https://github.com/pmndrs/zustand#fetching-everything says "bear in mind that it will cause the component to update on every state change!"
Any suggestion to add a note there?

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@MichielDeMey
Comment options

@dai-shi
Comment options

@imtrent
Comment options

@dai-shi
Comment options

Answer selected by MichielDeMey
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1044 on June 28, 2022 23:28.