Home > Back-end >  having error with getdefaultmiddleware of redux toolkit in adding logger conditionally
having error with getdefaultmiddleware of redux toolkit in adding logger conditionally

Time:06-23

Solved!

const config =
  process.env.NODE_ENV == "development"
    ? {
        reducer: persistedReducer,
        middleware: (getDefaultMiddleware) =>
          getDefaultMiddleware({
            serializableCheck: false,
          }).concat(logger)
      }
    : {
        reducer: persistedReducer,
        middleware: (getDefaultMiddleware) =>
          getDefaultMiddleware({
            serializableCheck: false,
          })
      };

export const store = configureStore(config);

Hi all my code is as follow I am deploying my app on Heroku but I am unable to add logger conditionally. Yes I need default middle ware because it is helping me with a firebase error that I don't remember now. Do anyone has any idea about this

export const store = configureStore({
    reducer: persistedReducer,
    middleware: (getDefaultMiddleware) => getDefaultMiddleware({
        serializableCheck: false,
    }).concat(logger),
  });

CodePudding user response:

The somewhat shorter option would be:

export const store = configureStore({
    reducer: persistedReducer,
    middleware: (getDefaultMiddleware) => {
      let middleware = getDefaultMiddleware({
        serializableCheck: false,
      });

      if (process.env.NODE_ENV == "development") {
        middleware = middleware.concat(logger);
      }
      return middleware;
    }

  });
  • Related