'use client'; import { useEffect } from 'react'; import { create } from 'zustand'; type Props = { year: Year; persons: Person[]; gifts: Gift[]; }; type State = Props & { hydrate: (data: Partial) => void; }; export const useGlobalStore = create((set) => ({ year: {} as Year, persons: [] as Person[], gifts: [] as Gift[], hydrate: (data: Partial) => set(data), })); export const GlobalStore = ({ children, year, persons, gifts }: Partial & { children: React.ReactNode }) => { const hydrate = useGlobalStore((s) => s.hydrate); useEffect(() => { hydrate({ year, persons, gifts }); }, []); return children; };