2024-06-27 23:31:59 +02:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2024-06-28 23:53:48 +02:00
|
|
|
import { configureStore } from '@reduxjs/toolkit';
|
2024-06-27 16:06:39 +02:00
|
|
|
import { rememberReducer, rememberEnhancer } from 'redux-remember';
|
|
|
|
import reducers from "@/features/product/productSlice"
|
|
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
2024-07-06 00:00:08 +02:00
|
|
|
import { ProductData } from "@/lib/dimensions_t";
|
2024-07-02 17:34:23 +02:00
|
|
|
import {Length} from "convert"
|
2024-06-27 16:06:39 +02:00
|
|
|
|
|
|
|
const rememberedKeys = ['products'];
|
|
|
|
|
|
|
|
const rootReducer = reducers;
|
|
|
|
|
2024-07-02 17:34:23 +02:00
|
|
|
const isBrowser = (typeof window !== "undefined");
|
|
|
|
|
2024-06-28 23:53:48 +02:00
|
|
|
export function setupStore(preloadedState = {
|
2024-06-30 18:37:27 +02:00
|
|
|
products: [] as ProductData[],
|
2024-07-02 17:34:23 +02:00
|
|
|
units: "ft" as Length,
|
2024-06-27 16:06:39 +02:00
|
|
|
}) {
|
|
|
|
return configureStore({
|
|
|
|
reducer: rememberReducer(reducers),
|
|
|
|
preloadedState,
|
|
|
|
enhancers: (getDefaultEnhancers) => getDefaultEnhancers().concat(
|
|
|
|
rememberEnhancer(
|
2024-07-04 17:29:47 +02:00
|
|
|
AsyncStorage,
|
2024-06-27 16:06:39 +02:00
|
|
|
rememberedKeys,
|
|
|
|
{
|
2024-07-02 17:34:23 +02:00
|
|
|
persistWholeStore: false,
|
|
|
|
},
|
2024-06-27 16:06:39 +02:00
|
|
|
)
|
|
|
|
),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export type RootState = ReturnType<typeof rootReducer>;
|
|
|
|
export type AppStore = ReturnType<typeof setupStore>;
|
|
|
|
export type AppDispatch = AppStore['dispatch'];
|
2024-06-27 23:31:59 +02:00
|
|
|
|
|
|
|
export const useAppDispatch = useDispatch.withTypes<AppDispatch>();
|
|
|
|
export const useAppSelector = useSelector.withTypes<RootState>();
|