import { useDispatch, useSelector } from "react-redux"; import { configureStore } from "@reduxjs/toolkit"; import { rememberReducer, rememberEnhancer } from "redux-remember"; import reducers, { DEFAULT_PRELOADED_STATE } from "@/features/product/productSlice"; import AsyncStorage from "@react-native-async-storage/async-storage"; const PERSIST_WHOLE_STORE = new Boolean(process.env.PERSIST_WHOLE_STORE).valueOf() || false; const rememberedKeys = ["products"]; const rootReducer = reducers; // const isBrowser = typeof window !== "undefined"; export function setupStore(preloadedState = DEFAULT_PRELOADED_STATE) { return configureStore({ reducer: rememberReducer(reducers), preloadedState, enhancers: (getDefaultEnhancers) => getDefaultEnhancers().concat( rememberEnhancer(AsyncStorage, rememberedKeys, { persistWholeStore: PERSIST_WHOLE_STORE, }) ), }); } export type RootState = ReturnType; export type AppStore = ReturnType; export type AppDispatch = AppStore["dispatch"]; export const useAppDispatch = useDispatch.withTypes(); export const useAppSelector = useSelector.withTypes();