What is the correct way to mutate the state in a zustand store? I see several examples where the state object is mutated directly, and others where a new object is returned from an action. In the example below both versions of increaseCats above work, but I'm wondering if there are any caveats using one or the other.
const useAnimalStore = create((set) => ({
cats: 0,
dogs: 0,
increaseCatsV1: () => set((state) => {
state.cats = state.cats + 1
}),
increaseCatsV2: () => set((state) => ({
...state,
cats: state.cats + 1
})),
})
)
Both version of increaseCats above work, but I'm wondering if there are any caveats using one or the other.