Last active
May 25, 2024 14:26
-
-
Save astrarudra/dc6650ed93e7e8b53dc0b913d023ab8a to your computer and use it in GitHub Desktop.
zustand-controller - Setup Slice
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
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