rekit
rekit copied to clipboard
Redux store persistance
When I'm changing the app location (through a link for instance), I see that the redux's store is not persisted.
I'm using the polyglot package, which build the polyglot node where the locale and more are stored, but when I click a link to change the location, I see that the node values are empty while before changing the location I had, at least, the locale stored.
It seems that I need something like redux-persist, but I'm wondering if I don't have an issue as I don't see an app built with Rekit without this feature.
Am I doing something wrong?
Did you use 'Link' component from 'react-redux-dom' for the navigation? Which doesn't actually refresh the page.
Nope, I'm using reactstrap to build the UI, in this case a NavItem.
OK so this makes my app to refresh. So when building an app with Rekit studio, by default, there isn't a persisting strategy, on page refresh the Redux store is cleared?
As a single page application, all page state is in memory which disappears after refresh. I don't think we need to persist the Redux store between refreshes. You may want to use <Link> from react-router-dom to navigate.
OK, I'm not sure this is fine for real medium and big apps, but I can see where it fits.
Then I would suggest to update the documentation explaining how to persist the store between page refreshes, or having a flag to pass to the app creation script which would add redux-persist and update the configStore.js file accordingly.
BTW I found the usage of history.push() from the source of the Link component from the react-redux-dom package.
I'm using it as much as I can.
But that doesn't change the purpose of this issue. Persisting the store should be implemented or at least documented.
@zedtux To persist your data you can use another approach, like localStorage.
I think that redux used to storage the data after a full refresh page.
I have a example:
actions
.login(data)
.then((res) => {
localStorage.setItem('user_data', JSON.stringify(res.data));
this.props.history.push('/lists');
})
.catch((error) => {
const inputsError = processRequestErrors(error.response.data);
this.setState({ inputsError: inputsError });
});
Now I can get the user_data after a refresh or if user close and reopen my site.
I'm using the redux-persist package which does this for me under the hood, but thank you @ianitsky for your comment.
Just to be sure : I'm not looking for a solution to persist the data, I'm opening a discussion about persisting the data as it isn't the case by default in Rekit.
@zedtux , Thanks for the tip. I'll try redux-persist
You're welcome @ianitsky.