News for hackers. Stuff that matters.
Re:Restoring React reducer state across browser sessions by mikewhy on Tuesday April 21, 2020 @04:07PM (#22938794)
We did the same at a previous company. This was Redux, so maybe a little different, but it went very smoothly.

We stored a subset of the redux store locally, and a further subset of that was sent to the server. This data is quite prone to changing, so a JSON field in the database is fine. You're not going to do any advanced querying / migrations on it.

Restoring was pretty easy:

- Try to grab from local storage

- Try to read from remote

- Merge those (let local overwrite remote)

- Pass the merged object through a migration function

- Pass the migrated data to `createStore`

The biggest pain point was dealing with TypeScript and migrations. The app only knows if the most recent store interface, so migration functions looked a lot like "old" javascript (`if (foo && foo.bar)`, `typeof foo === 'string'`, that sort of stuff).

Easy persistence / restoring is one of the many things I like about Redux.

Re:Restoring React reducer state across browser sessions by bitten on Wednesday April 22, 2020 @02:21AM (#22942811)
You can express a type as one of many interfaces, or use discriminated unions (https://www.typescriptlang.org/docs/handbook/advanced-types....) by using some unique version key to identify each interface. Then you'll have all the goodness of types back :)