Files
frontend/apps/as/src/shared/providers/store-provider.tsx
T
2026-05-12 14:31:45 +09:00

23 lines
614 B
TypeScript

"use client";
import { createContext, useRef } from "react";
import { createUserStore } from "../store";
type StoreContextType = {
userStore: ReturnType<typeof createUserStore>;
};
export const StoreContext = createContext<StoreContextType | undefined>(undefined);
export const StoreProvider = ({ children }: { children: React.ReactNode }) => {
const storeRef = useRef<StoreContextType | null>(null);
if (storeRef.current === null) {
storeRef.current = {
userStore: createUserStore(),
};
}
return <StoreContext.Provider value={storeRef.current}>{children}</StoreContext.Provider>;
};