import AsyncStorage from "@react-native-async-storage/async-storage"; import { create } from "zustand"; import { createJSONStorage, persist } from "zustand/middleware"; interface Family { family_id: number; } interface FamilyState { currentFamily: Family; setCurrentFamily: (family: Family) => void; clear: () => void; inFamily: () => boolean; getFamilyId: () => number; } const defaultFamily: Family = { family_id: 0, }; export const useFamilyStore = create()( persist( (set, get) => ({ currentFamily: defaultFamily, setCurrentFamily: (family) => set({ currentFamily: family, }), clear: () => set({ currentFamily: defaultFamily, }), inFamily: () => { const currentFamily = get().currentFamily; return currentFamily.family_id !== 0; }, getFamilyId: () => get().currentFamily.family_id, }), { name: "family-storage", storage: createJSONStorage(() => AsyncStorage), }, ), );