Closed kb1995 closed 2 years ago
Hey @kb1995, thanks for trying out the v2 beta!
You're correct, Date
is not in @prismicio/react
v2. The updated library only contains React-related code (components, hooks). Date
is function that converts a Date/Timestamp Prismic field to a Date object and is not React-specific.
The Date
helper is still available in @prismicio/helpers
. I recommend using @prismicio/helpers
v2 beta as it was rewritten alongside @prismicio/react
v2. In the beta, Date()
is renamed to asDate()
.
If you have any suggestions on what a <PrismicDate>
component could look like, please feel free to share!
A migration guide for the React and helpers library is being written that should help answer other questions like this. I'll be sure to cover your question in the guide.
In case you need a reference without having to jump into the source code, we have API references for each library here:
@prismicio/react
v2 beta - https://prismic.io/docs/technical-reference/prismicio-client?version=v6@prismicio/helpers
v2 beta - https://prismic.io/docs/technical-reference/prismicio-helpersJust a side note but the issue I see with providing a date component is that there are a lot of options when it comes to formatting dates with JavaScript: native ones, library-based ones, localization-based ones, etc.
Providing a date component would force us in making a choice here that might not fit every users' needs and/or taste, while also probably impacting negatively their bundle size.
The approach I would suggest instead is picking (or building) a date component that fits your needs, and then using it in combination with @prismicio/helpers
asDate()
helper, like @angeloashmore said ☺️
Yes, I totally agree with @lihbr
Using asDate() from the helpers package is sufficient. Let's close this for now :)
In v1, I've used the Date component on several occasions across my app
Looking at the source code, this component is missing. Any plans of adding it or I should create my own function to handle dates?