Are non-serializable objects in the store really that bad? #1654
-
Hello! I've recently switched from vanilla Redux to Redux Toolkit and I've started getting warnings about non-serializable objects in my Redux state. It turns out I've been keeping certain non-serializable objects in Redux for years, across multiple projects, and never encountered any issues with it. Specifically, I keep I see two options for resolving the warning:
Which option should I go with? By the way, I do use the Redux DevTools and have used redux-persist on one project. For redux-persist, I wrote a transform that converted between Moment objects and their ISO string representation. I do not use time travel debugging so I'm not sure if the non-serializable objects would work with it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is covered in the Redux FAQ entry https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state :
The other potential issue is that non-serializable values like classes or Dates are typically updated mutably. If you have selectors that directly return those values, and you happen to mutate them, your components likely won't re-render because So, long story short: yes you can get away with it, but it's definitely going against our recommended patterns because it has the potential to cause issues. I personally would prefer to keep date in the state as ISO strings for readability and serializability. |
Beta Was this translation helpful? Give feedback.
This is covered in the Redux FAQ entry https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state :