React-dates: Accept custom displayFormat instead using moment one.

Created on 28 Jan 2021  路  3Comments  路  Source: airbnb/react-dates

react-dates version
[email protected]

Describe the bug
You cannot use a custom format using your own function instead using moment on DateRangePicker.
I want to use Intl.format instead using moment.js and with current implementation it is impossible.
Source code (including props configuration)
Steps to reproduce the behavior:

<DateRangePicker
  startDate={this.state.startDate}
  startDateId="your_unique_start_date_id"
  endDate={this.state.endDate}
  endDateId="your_unique_end_date_id"
  onDatesChange={({ startDate, endDate }) => this.setState({ startDate, endDate })}
  focusedInput={this.state.focusedInput}
  onFocusChange={focusedInput => this.setState({ focusedInput })}
  displayFormat: date => formatDate(date)
/>

Most helpful comment

It doesn't matter if moment support it or not because this very easy modification will allow the consumer of the component to decide which is the formatter he wants to use. Since the interface already support a function as a parameter I don't understand why was implemented in this way in the first place.
In our specific case, for example, we need to use the component in a very long list of languages and in order to do that using moment formatter, we need to import all the localization files of moment. Using Intl allow us to already use the browser info for translate in any language without need to increase a lot our bundle size.

Seems to me a little odd that the component is very flexible and allow to change the presentation layer of all its part except the input value. We are using this component because allowed us to modify any part of it. There are props to change how every single element of the component is render. I don't understand why only the input value was left behind in this customization

All 3 comments

I can create a PR with the solution if you accept it!

If moment itself doesn鈥檛 support this kind of custom formatting, it wouldn鈥檛 make sense for react-dates to do so.

Once Temporal hits stage 3, we鈥檒l migrate fully over to Temporal, which already uses Intl for formatting.

It doesn't matter if moment support it or not because this very easy modification will allow the consumer of the component to decide which is the formatter he wants to use. Since the interface already support a function as a parameter I don't understand why was implemented in this way in the first place.
In our specific case, for example, we need to use the component in a very long list of languages and in order to do that using moment formatter, we need to import all the localization files of moment. Using Intl allow us to already use the browser info for translate in any language without need to increase a lot our bundle size.

Seems to me a little odd that the component is very flexible and allow to change the presentation layer of all its part except the input value. We are using this component because allowed us to modify any part of it. There are props to change how every single element of the component is render. I don't understand why only the input value was left behind in this customization

Was this page helpful?
0 / 5 - 0 ratings