PliWould/app/store.ts

33 lines
1.0 KiB
TypeScript
Raw Normal View History

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<RootState> = {
products: [] as Product[],
}) {
return configureStore({
reducer: rememberReducer(reducers),
// @ts-ignore
preloadedState,
enhancers: (getDefaultEnhancers) => getDefaultEnhancers().concat(
rememberEnhancer(
AsyncStorage,
rememberedKeys,
{
persistWholeStore: true,
}
)
),
});
}
export type RootState = ReturnType<typeof rootReducer>;
export type AppStore = ReturnType<typeof setupStore>;
export type AppDispatch = AppStore['dispatch'];