"use client";

import { Provider } from "react-redux";

// import { store } from "@/store/store";

import { useState } from 'react'

import { makeStore, PreloadedStateType } from '@/store/store'

export const ReduxProvider = ({ 
  children,
  preloadedState
}: { 
  children: React.ReactNode,
  preloadedState: PreloadedStateType
}) => {
  // return <Provider store={store}>{children}</Provider>;
  
  // const storeRef = useRef<AppStore>(undefined)
  // if (!storeRef.current) {
  //   // Create the store instance the first time this renders
  //   storeRef.current = makeStore(preloadedState)
  // }

  // return <Provider store={storeRef.current}>{children}</Provider>

  const [store] = useState(() => makeStore(preloadedState));

  return <Provider store={store}>{children}</Provider>
}
