With Redux RTK I'm getting this error "non-serializable value was detected in an action", however I just have Date's here, and they are serializable right? So wondering why this is?
in Redux RTK getting " non-serializable value was detected in an action" for a Date?
Asked Answered
Redux does not serialize objects for you
You are currently putting the class instance of the date so it's not serializable (because it's the class instance) however you can serialize a Date in Javascript
Are dates serializable?
You can call new Date().toISOString()
Which will produce a string
in the store
actually I'm not sure what you mean by "class instance of the date"? When I try this a date seems to serialize ok: const dateVar = new Date() console.log("Raw Date: ", dateVar) console.log("Sringified: ", JSON.stringify(dateVar)); –
Kwasi
I do not think redux is calling JSON.stringify for you –
Pedagogy
This is why you have to do
toISOString()
, JSON.stringify
, toJSON
etc... to serialize your date –
Pedagogy © 2022 - 2024 — McMap. All rights reserved.