'Can't change initialState in Redux slice

I created my themeSlice with hardCoded themes in mind initialState:{theme: "lightTheme"}. I quickly realized a better way to do it was by using a simple boolean value initialState: { darkTheme: false }.

After making the changes and running the program again, I still see in console "theme": "lightTheme"

I am using React-toolkit and RTK-Query in this project, not sure if my setup is the cause.

This is my Store setup:

const rootReducer = combineReducers({
  test: testSlice,
  theme: darkThemeSlice,
  [apiSlice.reducerPath]: apiSlice.reducer,
});

const persistConfig = {
  key: "root",
  storage: AsyncStorage,
};

const persistedReducer = persistReducer(persistConfig, rootReducer);

const store = configureStore({
  reducer: persistedReducer,
  devTools: true,
  middleware: (getDefaultMiddleWare) =>
    getDefaultMiddleWare({ serializableCheck: false }).concat(
      apiSlice.middleware
    ),
});

export default store;

I cleared cache and re-ran my app, and nothing changed.

Any idea what is happening here?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source