How to handle DateTime fields of type Date on the client-side (convert ISO string) #6763
Unanswered
bennettdams
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How do you handle fields of type
Date
on your client-side?Imagine a field with
DateTime
in the schema. The Prisma Client with TypeScript shows the field of typeDate
later, but when you fetch the data client-sided, it will be serialized to an (ISO) string.Here is a schema:
The data is provided via a Next.js API route:
...with a standard fetch:
...together with a custom hook and React Query:
I understand that I can easily convert the ISO string to a date, but where is the best place to do that?
This is a fairly simple example, but I'd need to do that for every schema model and every date field I'll ever use, right? There has to be a better way than manually creating dates after fetching on the client.
Beta Was this translation helpful? Give feedback.
All reactions