How to use the @reduxjs/toolkit.getDefaultMiddleware function in @reduxjs/toolkit

To help you get started, we’ve selected a few @reduxjs/toolkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bunkerchat / bunker / src / store.js View on Github external
import { configureStore, getDefaultMiddleware } from "@reduxjs/toolkit";
import { createBrowserHistory } from "history";
import { connectRouter, routerMiddleware } from "connected-react-router";
import rootReducer from "./rootReducer";

const history = createBrowserHistory();

const middleware = getDefaultMiddleware({
	// TODO: a few reducers are not correctly immutable or serializable. Fix those and turn this back on
	// emoticonPicker is one
	immutableCheck: false,
	serializableCheck: false
});

const store = configureStore({
	reducer: connectRouter(history)(rootReducer),
	middleware: [routerMiddleware(history), ...middleware]
});

if (process.env.NODE_ENV === "development" && module.hot) {
	module.hot.accept("./rootReducer", () => {
		const newRootReducer = require("./rootReducer").default;
		store.replaceReducer(newRootReducer);
	});
github chaos-mesh / chaos-mesh / ui / src / store.ts View on Github external
import { AnyAction, configureStore, getDefaultMiddleware } from '@reduxjs/toolkit'
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'

import rootReducer from 'reducers'

const middlewares = getDefaultMiddleware({
  serializableCheck: false, // warn: in order to use the global ConfirmDialog, disable the serializableCheck check
})

const genStore = () => {
  if (process.env.NODE_ENV === 'development') {
    const { createLogger } = require('redux-logger')

    const logger = createLogger({
      predicate: (_: any, action: AnyAction) => {
        if (action.type.includes('pending')) {
          return false
        }

        return true
      },
    })
github jellyfin / jellyfin-react-client / src / utilities / storage / store.ts View on Github external
key: "connectionStatus",
    storage: sensitiveStorage,
    stateReconciler: hardSet,
    blacklist: ["connectStatus", "apiInitialized"]
};

const rootReducer = combineReducers({
    authCredentials: persistReducer(authPersistConfig, authReducer),
    connectionStatus: persistReducer(connectPersistConfig, connectReducer),
});

const persistedReducer = persistReducer(rootPersistConfig, rootReducer);

const store = configureStore({
    reducer: persistedReducer,
    middleware: getDefaultMiddleware({
        serializableCheck: {
            // Ignore actions from redux-persist
            ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER]
        }
    })
})
const persistor = persistStore(store, null, () => {
    store.dispatch(initApiClient())
});

export type RootState = ReturnType
export const useSelector: TypedUseSelectorHook = useReduxSelector

export { store, persistor };
github pipe-cd / pipe / pkg / app / web / test-utils.tsx View on Github external
configureStore,
  DeepPartial,
  EnhancedStore,
  getDefaultMiddleware,
  Store,
  ThunkDispatch,
} from "@reduxjs/toolkit";
import { render, RenderOptions, RenderResult } from "@testing-library/react";
import { Provider } from "react-redux";
import configureMockStore from "redux-mock-store";
import { reducers } from "./src/modules";
import type { AppState } from "./src/store";
import { theme } from "./src/theme";
import { thunkErrorHandler } from "./src/middlewares/thunk-error-handler";

const middlewares = getDefaultMiddleware({
  immutableCheck: false,
  serializableCheck: false,
});

export const createReduxStore = (
  preloadedState?: Partial
): EnhancedStore => {
  return configureStore({
    reducer: reducers,
    middleware: [...middlewares, thunkErrorHandler],
    preloadedState,
  });
};

const store = createReduxStore();
const baseState = store.getState();
github pluto-net / scinapse-web-client / app / store / store.tsx View on Github external
public initializeStore() {
    const loggerMiddleware = createLogger({ collapsed: true });
    const preloadedState = this.getBrowserInitialState();
    const middlewares = [
      ...getDefaultMiddleware({
        thunk: {
          extraArgument: {
            axios: getAxiosInstance(),
          },
        },
      }),
      ReduxNotifier,
      setUserToTracker,
    ];
    if (EnvChecker.isLocal() || EnvChecker.isDev()) {
      middlewares.push(loggerMiddleware);
    }

    return configureStore({
      reducer: rootReducer,
      middleware: middlewares,
github pluto-net / scinapse-web-client / app / store / serverStore.tsx View on Github external
public static getStore(extraArgument: ThunkExtraArgument) {
    return configureStore({
      reducer: rootReducer,
      devTools: false,
      preloadedState: initialState,
      middleware: [
        ...getDefaultMiddleware({
          thunk: {
            extraArgument,
          },
        }),
      ],
    });
  }
}