Zustand doesn't trigger component update when state is class based #2539
Unanswered
pablojakub
asked this question in
Q&A
Replies: 1 comment
-
@pablojakub don't use classes don't do that to you |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I want to store objects in Zustand created from class:
const initialState: InitialState = { animals: Animal[], };
Store is feeded by pushing new classess to the collection of animals. Whenever I update any object it doesn't trigger components update. Neither using immer nor typical set state:
updateAnimal: (animalld) => set((state: AnimalSlice) => { const newAnimals = [...state.animalSlice.animals]; const animalToUpdate = newAnimals .find((animal) => animal.id === animalId); const animalToUpdateIndex = newAnimals .findIndex((animal) => animal.id === animalId); if (animalToUpdate ) { animalToUpdate .name = 'Cow'; newAnimals [animalToUpdateIndex ] = animalToUpdate ; } return { animalSlice: { actions: { ...state.animalSlice.actions }, selectors: { ...state.animalSlice.selectors }, animals: newAnimals }, }; }),
In devtools I can see that name changed to "Cow" but it doesn't trigger rerender of given component.
Can anyone has that kind of situation?
Beta Was this translation helpful? Give feedback.
All reactions