Vercel/src/state/AppStateProvider.tsx

39 lines
907 B
TypeScript

'use client';
import { useState, useEffect, ReactNode } from 'react';
import { AppStateContext } from './AppState';
import { AnimationConfig } from '@/components/AnimateItems';
import usePathnames from '@/utility/usePathnames';
export default function AppStateProvider({
children,
}: {
children: ReactNode
}) {
const { previousPathname } = usePathnames();
const [hasLoaded, setHasLoaded] = useState(false);
const [nextPhotoAnimation, setNextPhotoAnimation] =
useState<AnimationConfig>();
useEffect(() => {
setHasLoaded?.(true);
}, [setHasLoaded]);
return (
<AppStateContext.Provider
value={{
previousPathname,
hasLoaded,
setHasLoaded,
nextPhotoAnimation,
setNextPhotoAnimation,
clearNextPhotoAnimation: () => setNextPhotoAnimation?.(undefined),
}}
>
{children}
</AppStateContext.Provider>
);
};