rekit icon indicating copy to clipboard operation
rekit copied to clipboard

Redux store persistance

Open zedtux opened this issue 6 years ago • 9 comments

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?

zedtux avatar Dec 09 '18 17:12 zedtux

Did you use 'Link' component from 'react-redux-dom' for the navigation? Which doesn't actually refresh the page.

supnate avatar Dec 10 '18 04:12 supnate

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?

zedtux avatar Dec 10 '18 06:12 zedtux

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.

supnate avatar Dec 11 '18 02:12 supnate

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.

zedtux avatar Dec 11 '18 05:12 zedtux

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 avatar Dec 17 '18 13:12 zedtux

@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.

ianitsky avatar Dec 17 '18 14:12 ianitsky

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 avatar Dec 17 '18 14:12 zedtux

@zedtux , Thanks for the tip. I'll try redux-persist

ianitsky avatar Dec 18 '18 10:12 ianitsky

You're welcome @ianitsky.

zedtux avatar Dec 18 '18 10:12 zedtux