Files
golunteer/client/src/Zustand.ts
2025-01-12 02:01:14 +00:00

48 lines
787 B
TypeScript

"use client";
import { create } from "zustand";
import { persist } from "zustand/middleware";
export interface EventData {
id: number;
date: string;
tasks: Partial<Record<string, string | null>>;
description: string;
}
export interface User {
userName: string;
admin: boolean;
}
interface Zustand {
user: User | null;
reset: (zustand?: Partial<Zustand>) => void;
}
const initialState = {
user: null,
};
const zustand = create<Zustand>()(
persist(
(set) => ({
...initialState,
reset: (newZustand) =>
set({
...initialState,
...newZustand,
}),
}),
{
name: "golunteer-storage",
partialize: (state) =>
Object.fromEntries(
Object.entries(state).filter(([key]) => ["user"].includes(key)),
),
},
),
);
export default zustand;