alan2207 / bulletproof-react

🛡️ ⚛️ A simple, scalable, and powerful architecture for building production ready React applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why we need to use number for createdAt in BaseEntity class

galih56 opened this issue · comments

Why we use number instead of Date Object or Datetime string?
Any explaination on this?

Thank you

hey @galih56

This was because the dates are stored as timestamps, which are numbers instead of dates. Both options are valid, it would be up to the API implementation how to implement it.

If I want to use a Datetime string to serve dates from an endpoint, do I have to convert the dates into Date Objects for every fetch? For now, I have to make a converter that I use in the axios interceptor to convert the dates for every HTTP request, whether it's a POST, GET, PUT, or DELETE request. But I'm still curious to ask this question.

If you really want dates as date objects, consider treating them that way at the API level, so you don't do any conversion on the FE.

But if you don't control the API data and really want it, then transforming the response makes sense. In that case, you can also consider using zod for transforming and validating your responses.