1

I am developing a Next.js app where I use Redux Toolkit. At the moment I am using redux in a dumb way, so that I almost don't need it at all: every time the app reloads I lose all I had in my redux store and I reinitialize the store with data I take from either the local storage or a database.

I spent days reading docs, questions, GitHub issues and examples and I really don't get how I could possibly reuse the redux store, rather than losing it and having to reinitialize it.

I came to know I could use some tool like redux-wrapper, but I wonder if these tools really reuse the store or they just automatize what I am already doing.

At the end my question boils down to whether, while in the process of reloading a page, there is a time frame in which I can still access the old store and yet have the possibility to somehow dispatch towards the new one.

anotherOne
  • 1,513
  • 11
  • 20
  • 2
    Why would you waste days of expensive development time when other people already have put dozens or hundreds of hours into a good working solution? You can directly access the accumulated knowledge and learnings of a library that has to work in all kinds of edge case scenarios over hundreds of users. This is even server-side rendering, so bundle size isn't even an issue! – phry Jun 20 '21 at 21:54
  • @phry you are right, if I was being paid for making this app I would have definitely took advantage of the solid library that accounts for all kinds of edge cases. But since there's no business behind my work and I have already spent dozens of hours making a good working solution, I would not refactor my code just to account for some edge case, but I would definitely refactor it to recycle the store and make redux really worth to be used. – anotherOne Jun 20 '21 at 22:17
  • My general understanding of next-redux-wrapper etc is that the SSR-built version of the page uses a new store for every page, as each page needs to be independent. But when the user is actually visiting the page and going from one page to another, the redux store *is* persisted. – Linda Paiste Jun 26 '21 at 20:36
  • If you want a deeper understanding of the differences you should read through the next-redux-wrapper docs, in particular the [How it Works](https://github.com/kirill-konshin/next-redux-wrapper#how-it-works) and [Motivation](https://github.com/kirill-konshin/next-redux-wrapper#motivation) sections. – Linda Paiste Jun 26 '21 at 20:44
  • @LindaPaiste Thank you very much for the resources! However I don't get from where the wrapper gets the old store when the page reloads. I think it is stated somewhere in the **Phase 1** of the [How it Works](https://github.com/kirill-konshin/next-redux-wrapper#how-it-works) section, but I really don't get it. – anotherOne Jun 26 '21 at 22:33

0 Answers0