Skip to content

Instantly share code, notes, and snippets.

@astrarudra
Last active May 25, 2024 14:26
Show Gist options
  • Save astrarudra/dc6650ed93e7e8b53dc0b913d023ab8a to your computer and use it in GitHub Desktop.
Save astrarudra/dc6650ed93e7e8b53dc0b913d023ab8a to your computer and use it in GitHub Desktop.
zustand-controller - Setup Slice
export const generalSlice = (set) => ({
fsLoader: null, // ur store variables
demoState: 0,
demoData: "I am connected to Store...",
/* Functions - let's not call them reducers,
brings back redux memories - yuck! 🤮 */
// Dynamic setState for root variables
setState: (data) => set((s: any) => {
Object.keys(data).forEach((key) => {
s[key] = data[key]
}) // Use this fn - if ur lazy 😜
}),
setLoader: (message) => set((s) => {
s.fsLoader = message // The Usual Way
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment