Closed Melkeydev closed 2 years ago
const defaultState = { version: APP_VERSION, something: [], otherThing: true } const cachedState = JSON.parse(localStorage.getItem('state')) let initialState = defaultState if (cachedState?.version === APP_VERSION) { initialState = cachedState } else { localStorage.setItem('state', JSON.stringify(initialState)) } export const useStore = create(set => ({ ...initialState, someMethod(thing) { set({ thing }) } }))```