Skip to content

State change does not cause re-render #1653

Answered by dai-shi
ben4d85 asked this question in Q&A
Discussion options

You must be logged in to vote

Zustand is built on immutability (as well as React). You can't mutate your state.

useAnimalsStore.setState((state) => ({
  animals: state.animals.filter((animal) => animal.id === animalId ? { ...animal, clicked: true } : animal)
}))

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@cristian-eriomenco
Comment options

@dbritto-dev
Comment options

Answer selected by ben4d85
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
5 participants