Search code examples
reactjsreduxjson-deserializationredux-toolkitredux-persist

Adding custom serializer to different parts of a redux state


Suppose I created a slice which is used to manage pets, and it uses Date as one of the properties of the pet.

Given that redux by itself is not able to serialize Date, I would like to have a solution which allows me to supply a custom serializer/de-serializer for Date.

How would I do this?


Solution

  • There is no such thing as a "custom serializer/deserializer" for a Redux store by itself. The Redux state contains exactly what your slice reducers return, with no other transformations.

    We normally recommend that you keep date values in state as either ISO strings or numeric timestamps, and convert back to dates in components if actually needed.