Next.js Discord

Discord Forum

How do you de/serialize dates with react-query + SSR?

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
How do you de/serialize dates with react-query + SSR? I'm using QueryClientProvider / Hydrate providers

5 Replies

@Northeast Congo Lion How do you de/serialize dates with react-query + SSR? I'm using `QueryClientProvider` / `Hydrate` providers
Have you tried just parsing the date into number and pass them into a client component to be converted back to the Date object
@Northeast Congo Lion How do you de/serialize dates with react-query + SSR? I'm using `QueryClientProvider` / `Hydrate` providers
Ah btw as a tip, if you arent already doing this and are going to be storing dates in database: convert them into the exact time in UTC and then store them as a string
@aardani Have you tried just parsing the date into number and pass them into a client component to be converted back to the Date object
Northeast Congo LionOP
No, that's what I'm asking. I don't want to have to re-deserialize every object with date fields in every component that needs the server data
@Northeast Congo Lion Postgres has a DateTime column, no need for string conversion
So does Mysql. I was just adding that you should be careful just in case cause on some timezones, if you dont do that you are gonna end up with the wrong date. Store them as DateTime but just make sure its converting it correctly.