question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessing persistor in unconnected part of app?

See original GitHub issue

In my app I call persistStore when initializing store for the first time

// store.js
export default function configureStore(initialState = {}, history) {
...
const store = createStore(
    createReducer(),
    fromJS(initialState),
    composeEnhancers(...enhancers) // includes autoRehydrate
  );

const persistor = persistStore(store, { storage: localForage, whitelist: ['auth', 'support'] }, (a, b) => {
     console.log('Redux-Persist loaded state');
   });
...
return store;
}
// app.js
...
const initialState = {};
const store = configureStore(initialState, browserHistory);
const history = syncHistoryWithStore(browserHistory, store, {
 selectLocationState: makeSelectLocationState(),
});
...
const render = (messages) => {
 ReactDOM.render(
   <Provider store={store}>
     <LocaleProvider locale={enUS}>
       <Router
         history={history}
         routes={createRoutes(store)}
         render={
            applyRouterMiddleware(useScroll())
          }
       />
     
     </LocaleProvider>
   </Provider>,
    document.getElementById('app')
  );
};

Because I need REHYDRATE to fire so I can get stored user auth info and skip login, etc.

If there is no user auth info (IE user is logged out) I would like to do something similar to https://github.com/rt2zz/redux-persist/issues/253 and call persistor.pause() if the user has not checked “remember me” when they login.

However in the documentation I don’t see a clear way to access persistor after it’s initially created. How can I do this? Does it require recreating my entire store using the current store as initial state? just so i can get another persistor?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
rt2zzcommented, Oct 24, 2017

couple of options:

  1. if your config is statically defined, you can use purgeStoredState as follows
import { purgeStoredState } from 'redux-persist'
import { persistConfig } from 'somewhere you defined it'

// ...

purgeStoredState(persistConfig)
  1. expose persistor via context, much like react-redux does for store

I would recommend option 1 when possible

1reaction
Viral-Inccommented, May 17, 2017

@FoxxMD me using context is kind of shameful too, but, basically I declared store as a contextType on a Purge class component:

import React, {Component} from 'react'
import {persistStore} from 'redux-persist'
import './purge.css'
import PropTypes from 'prop-types'

class Purge extends Component {

  handleSubmit = (e) => {
    e.preventDefault();
    persistStore(this.context.store).purge()
  };

  render() {
    return (
      <div id="pur-d1a">
        <div id="pur-d2a">
          <form onSubmit={this.handleSubmit}>
            <input type="submit" value="purge"/>
          </form>
        </div>
      </div>
    )
  };
}

Purge.contextTypes = {
  store: PropTypes.object
};

export default Purge
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my website not loading anymore after using redux-persist
Your implementation seems to be wrong. Let's review them step by step: First, create a persistedReducer :
Read more >
Persist state with Redux Persist using Redux Toolkit in React
Persisting state with Redux Persist. First, we'll add Redux Persist to our app with the following command: $ npm i redux-persist.
Read more >
A Redux implementation with the new kid on the block: Flutter
Here, we will look into how to extend an app with a Redux store, Thunk future actions and the Redux Persistor.
Read more >
System event codes and messages - TechDocs - Broadcom Inc.
Incidents folder The Incident Persister is unable to access the incident folder {0}. Check folder permissions. 1806. Response rule processing ...
Read more >
Micro Focus Security ArcSight ESM Installation Guide
Installing Software ESM in Distributed Correlation Mode Using the. Configuration Wizard. 53. Installing ESM on the Persistor Node.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found