first commit
This commit is contained in:
21
components/StoreProvider.tsx
Normal file
21
components/StoreProvider.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
"use client";
|
||||
import { useRef } from "react";
|
||||
import { Provider } from "react-redux";
|
||||
import { makeStore, AppStore } from "@/lib/store";
|
||||
import { restoreSession } from "@/lib/features/auth/authSlice";
|
||||
|
||||
export default function StoreProvider({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const storeRef = useRef<AppStore>(null);
|
||||
if (!storeRef.current) {
|
||||
// Create the store instance the first time this renders
|
||||
storeRef.current = makeStore();
|
||||
// Restore session from localStorage
|
||||
storeRef.current.dispatch(restoreSession());
|
||||
}
|
||||
|
||||
return <Provider store={storeRef.current}>{children}</Provider>;
|
||||
}
|
||||
Reference in New Issue
Block a user