rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.9k stars 862 forks source link

Option to disable storage creation error for dynamic stores #1467

Open Bram-Zijp opened 4 months ago

Bram-Zijp commented 4 months ago

My store is created with or without redux-persist dynamically. It would be nice to disable storage creation errors when a store is initialized without using the redux-persist persistedReducer and/or preferably when persistStore(store) is not called.

Example:

import storage from "redux-persist/lib/storage";
import {
  persistStore,
  persistReducer,
} from "redux-persist";
const persistedReducer = persistReducer(
  {
    key: "root",
    version: 1,
    storage,
    // ignore error option here?
  },
  rootReducer
);
export const createStore = (
  persistToLocalStorage: boolean = false,
) => {
  const store = configureStore({
    reducer: persistToLocalStorage
      ? persistedReducer
      : rootReducer,
  });
  // only error here when persistStore?
  const persistor = persistToLocalStorage ? persistStore(store) : undefined;
  return { store, persistor };
};