Skip to content

Instantly share code, notes, and snippets.

@aasumitro
Created February 10, 2025 09:35
Show Gist options
  • Select an option

  • Save aasumitro/59c4a3f3e632f02eff91c89e77716f62 to your computer and use it in GitHub Desktop.

Select an option

Save aasumitro/59c4a3f3e632f02eff91c89e77716f62 to your computer and use it in GitHub Desktop.
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