Last active
March 24, 2024 08:44
-
-
Save livemehere/d683aeff483b2ab45519c4699495ca16 to your computer and use it in GitHub Desktop.
zustand boiler template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { create } from "zustand"; | |
import { devtools } from "zustand/middleware"; | |
import { immer } from "zustand/middleware/immer"; | |
type State = { | |
isDarkMode: boolean; | |
}; | |
type Actions = { | |
toggleDarkMode: () => void; | |
reset: () => void; | |
}; | |
const initialState: State = { | |
isDarkMode: false, | |
}; | |
export const useGlobalStore = create<State & Actions>()( | |
devtools( | |
immer((set) => ({ | |
...initialState, | |
reset: () => set(initialState, false, "reset"), | |
toggleDarkMode: () => | |
set( | |
(state) => { | |
state.isDarkMode = !state.isDarkMode; | |
}, | |
false, | |
"toggleDarkMode", | |
), | |
})), | |
{ name: "globalStore" }, | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment