Hi,
So I've got store with some variables, and a reset function. In the reset function when I try to set state to const with initialState for some reason it doesn't work, but when I manually write the same content it does. Why?
Initial state:
const initState = {
currentTick: 0,
// speed
speed: 3,
// interval ref
interval: 0,
menu: true,
// starting snake
snake: [[10, 2]],
};
Reset function that doesn't work:
const useGameStateStore = create<GameState>()((set) => ({
...initState,
reset: () =>
set((state) => ({
...initState,
})),
}));
Reset function that does work:
const useGameStateStore = create<GameState>()((set) => ({
...initState,
reset: () =>
set((state) => ({
currentTick: 0,
// speed
speed: 3,
// interval ref
interval: 0,
menu: true,
// starting snake
snake: [[10, 2]],
})),
}));