prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
154 stars 40 forks source link

Date Component in v2? #102

Closed kb1995 closed 2 years ago

kb1995 commented 2 years ago

In v1, I've used the Date component on several occasions across my app

import { Date as ParseDate } from 'prismic-reactjs';

Looking at the source code, this component is missing. Any plans of adding it or I should create my own function to handle dates?

angeloashmore commented 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:

lihbr commented 2 years ago

Just 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 ☺️

kb1995 commented 2 years ago

Yes, I totally agree with @lihbr

Using asDate() from the helpers package is sufficient. Let's close this for now :)