Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { configureStore, getDefaultMiddleware } from "@reduxjs/toolkit";
import { thunkErrorHandler } from "./middlewares/thunk-error-handler";
import { reducers } from "./modules";
export const store = configureStore({
reducer: reducers,
devTools: process.env.NODE_ENV === "development",
middleware: [
...getDefaultMiddleware({}),
thunkErrorHandler,
// @see https://redux-toolkit.js.org/usage/usage-with-typescript#correct-typings-for-the-dispatch-type
] as const,
});
export type AppState = ReturnType;
export type AppDispatch = typeof store.dispatch;
// See the following guides for an explanation:
// https://redux-starter-kit.js.org/usage/usage-guide
// https://redux.js.org/recipes/usage-with-typescript
import { configureStore, getDefaultMiddleware } from "@reduxjs/toolkit";
import { combineReducers } from "redux";
// Reducers:
import { searchReducer } from "./search/reducer";
const rootReducer = combineReducers({
search: searchReducer,
});
const store = configureStore({
reducer: rootReducer,
middleware: [...getDefaultMiddleware()],
});
export type AppState = ReturnType;
export default store;
export const createReduxStore = (
preloadedState?: Partial
): EnhancedStore => {
return configureStore({
reducer: reducers,
middleware: [...middlewares, thunkErrorHandler],
preloadedState,
});
};
export const initStore = ( props = {} ) => {
const initialState = {
...paths.UI.createTree( INITIAL_UI_STATE ),
data: {
fieldTypes: { ...props.config?.fieldTypes || {} },
relatedObjects: { ...props.config?.relatedObjects || {} },
},
...omit( props?.config || {}, [ 'fieldTypes', 'relatedObjects' ] ),
};
const reduxStore = configureStore( {
reducer,
middleware: [ apiMiddleware ],
preloadedState: initialState,
} );
const mappedSelectors = Object.keys( selectors ).reduce( ( acc, selectorKey ) => {
acc[ selectorKey ] = ( ...args ) =>
selectors[ selectorKey ]( reduxStore.getState(), ...args );
return acc;
}, {} );
const mappedActions = Object.keys( actions ).reduce( ( acc, actionKey ) => {
acc[ actionKey ] = ( ...args ) => reduxStore.dispatch( actions[ actionKey ]( ...args ) );
return acc;
}, {} );
import { configureStore, Action } from '@reduxjs/toolkit';
import { ThunkAction } from 'redux-thunk';
import rootReducer, { RootState } from './RootReducer';
const store = configureStore({
reducer: rootReducer,
});
if (process.env.NODE_ENV === 'development' && module.hot) {
module.hot.accept('./RootReducer', () => {
const newRootReducer = require('./RootReducer').default;
store.replaceReducer(newRootReducer);
});
}
export type AppDispatch = typeof store.dispatch;
export type AppThunk = ThunkAction>;
export default store;
import { configureStore } from '@reduxjs/toolkit';
import configReducer from './features/config';
import userReducer from './features/user';
const store = configureStore({
reducer: {
config: configReducer,
user: userReducer,
},
})
export type RootState = ReturnType
export type AppDispatch = typeof store.dispatch
export default store;
export const init = () => {
const sagaMiddleware = createSagaMiddleware()
const store = configureStore({
reducer: combineReducers(reducers),
middleware: [sagaMiddleware],
})
sagaMiddleware.run(rootSaga)
return store
}
import { configureStore, Action } from '@reduxjs/toolkit'
import { ThunkAction } from 'redux-thunk'
import rootReducer, { RootState } from './rootReducer'
const store = configureStore({
reducer: rootReducer
})
if (process.env.NODE_ENV === 'development' && module.hot) {
module.hot.accept('./rootReducer', () => {
const newRootReducer = require('./rootReducer').default
store.replaceReducer(newRootReducer)
})
}
export type AppDispatch = typeof store.dispatch
export type AppThunk = ThunkAction>
export default store
export const init = () => {
const sagaMiddleware = createSagaMiddleware()
const store = configureStore({
reducer: combineReducers(reducers),
middleware: [sagaMiddleware],
})
sagaMiddleware.run(rootSaga)
return store
}
const { createLogger } = require('redux-logger')
const logger = createLogger({
predicate: (_: any, action: AnyAction) => {
if (action.type.includes('pending')) {
return false
}
return true
},
})
middlewares.push(logger)
}
const store = configureStore({
reducer: rootReducer,
middleware: middlewares,
devTools: process.env.NODE_ENV !== 'production',
})
return store
}