Open FoxxMD opened 7 years ago
I'm basically wondering the same thing / having a hard time ): edit: i used context.store and it worked
@Viral-Inc can you expand on that please? Right now I'm setting the persistor as a global variable on window
and it feels shameful.
@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
Me too. Any tips?
couple of options:
purgeStoredState
as follows
import { purgeStoredState } from 'redux-persist'
import { persistConfig } from 'somewhere you defined it'
// ...
purgeStoredState(persistConfig)
2. expose persistor via context, much like react-redux does for store
I would recommend option 1 when possible
In my app I call
persistStore
when initializing store for the first timeBecause 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 anotherpersistor
?