I have a react app like where I have App.js
which includes my Headers
and Footers
..
In there I am storing my state
to local storage.. After storing I can retrieve it ..
But I am having problem on loading it.. In my browser when I do localstorage['key']
it gives me the data but I am unable to load.
Where should I load it first ?
I have Root.js
:
class Root extends Component {
render() {
const { store } = this.props
return (
<Provider store={store}>
<ReduxRouter />
</Provider>
)
}
}
Root.propTypes = {
store: PropTypes.object.isRequired
}
export default Root
and index.js
at outer level :
const store = configureStore()
render(
<Root store={store} />,
document.getElementById('root')
)
Where should I load my localStorage
?
Need help . I need to know what is called first in react so that I can make a call to load localStorage
there .. If it is not bad idea
You're using redux, so you should read the data as the result of an action.
The simplest way to make this work would be:
ReduxRouter
there should be a connected component. See docs
componentDidMount
to call an action getStuffFromLocalstorage
. See React lifecycle events
It might be an antipattern to do it in your reducer, but it will at least make the redux-flow go around.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With