import { combineReducers, configureStore } from '@reduxjs/toolkit'; import { rememberReducer, rememberEnhancer } from 'redux-remember'; import reducers from "@/features/product/productSlice" import AsyncStorage from '@react-native-async-storage/async-storage'; import { Product } from "@/lib/product"; const rememberedKeys = ['products']; const rootReducer = reducers; export function setupStore(preloadedState: Partial = { products: [] as Product[], }) { return configureStore({ reducer: rememberReducer(reducers), // @ts-ignore preloadedState, enhancers: (getDefaultEnhancers) => getDefaultEnhancers().concat( rememberEnhancer( AsyncStorage, rememberedKeys, { persistWholeStore: true, } ) ), }); } export type RootState = ReturnType; export type AppStore = ReturnType; export type AppDispatch = AppStore['dispatch'];