Add initial project setup with PocketBase integration, global state management, and UI components for gift tracking
This commit is contained in:
32
src/app/store/global.tsx
Normal file
32
src/app/store/global.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
import { create } from 'zustand';
|
||||
|
||||
type Props = {
|
||||
year: Year;
|
||||
persons: Person[];
|
||||
gifts: Gift[];
|
||||
};
|
||||
|
||||
type State = Props & {
|
||||
hydrate: (data: Partial<Props>) => void;
|
||||
};
|
||||
|
||||
export const useGlobalStore = create<State>((set) => ({
|
||||
year: {} as Year,
|
||||
persons: [] as Person[],
|
||||
gifts: [] as Gift[],
|
||||
|
||||
hydrate: (data: Partial<Props>) => set(data),
|
||||
}));
|
||||
|
||||
export const GlobalStore = ({ children, year, persons, gifts }: Partial<Props> & { children: React.ReactNode }) => {
|
||||
const hydrate = useGlobalStore((s) => s.hydrate);
|
||||
|
||||
useEffect(() => {
|
||||
hydrate({ year, persons, gifts });
|
||||
}, []);
|
||||
|
||||
return children;
|
||||
};
|
||||
Reference in New Issue
Block a user