Created
February 10, 2025 09:35
-
-
Save aasumitro/59c4a3f3e632f02eff91c89e77716f62 to your computer and use it in GitHub Desktop.
This file contains hidden or 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"; | |
| interface LoadState { | |
| [key: string]: boolean; | |
| } | |
| interface States { | |
| states: LoadState; | |
| } | |
| interface Actions { | |
| setState: (key: string, value: boolean) => void; | |
| resetState: () => void; | |
| } | |
| export const useGlobalActionStore = create<States & Actions>((set) => ({ | |
| states: {}, | |
| setState: (key: string, value: boolean) => | |
| set((state) => { | |
| const newStates = { ...state.states }; | |
| if (value) { | |
| newStates[key] = value; | |
| } else { | |
| delete newStates[key]; | |
| } | |
| return { states: newStates }; | |
| }), | |
| resetState: () => set({ states: {} }), | |
| })); | |
| // other comm .tsx | |
| const AvailabilityModalState = "modal_avail_state" | |
| const { states, setState } = useGlobalActionStore(); | |
| setState(AvailabilityModalState, true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment