I never really understood one of the four Redux essential best practices, nor did I actually really try to. Until I had to learn it the hard way, when

The redux best practice “Do Not Put Non-Serializable Values in State or Actions” explained

submited by
Style Pass
2021-06-23 13:00:05

I never really understood one of the four Redux essential best practices, nor did I actually really try to. Until I had to learn it the hard way, when I was facing a weird bug. 

As I did not understand where it came from, I did what most serious developers in this situation do: I ran my code again without making any change, hoping for it to work. It did not.

Actually, redux-persist documentation explains that  they are not able to persist non-serializable values, like my Date object apparently is.

But that’s fine because they should never have been in our stores anyway, persistence or not: it is a redux best practice:  “Do Not Put Non-Serializable Values in State or Actions”. Just like “Promises, Symbols, Maps/Sets, functions, or class instances”, Date objects should not be saved in our stores. This is one of the  four essential best practices.

Some reasons for this best practice were very well explained. But for some of them, I had to dig a little bit further. So I thought I’d share what I've learnt along the road.

Leave a Comment