You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're using react-datepicker in an app where the global context should not be modified. It looks like in v2, non-English locales won't work unless the locales are registered ahead of time on the global window object:
This does not align with how date-fns itself handles locales. In their docs, they have this example, where the locale object is passed directly as an argument, without going through an indirection layer:
vardistanceInWords=require('date-fns/distance_in_words')// Require Esperanto localevareoLocale=require('date-fns/locale/eo')varresult=distanceInWords(newDate(2016,7,1),newDate(2015,0,1),{locale: eoLocale}// Pass the locale as an option)//=> 'pli ol 1 jaro'
The react-datepicker equivalent would look something like this:
Allowing that usage would let you manage locales with all the flexibility that date-fns itself allows. Supporting it in a backwards-compatible way would (at first glance) require only one change, here, to something like this:
exportfunctiongetLocaleObject(localeSpec){if(typeoflocaleSpec==='string')// Treat it as a locale name registered by registerLocalereturnwindow.__localeData__ ? window.__localeData__[localeSpec] : null;else// Treat it as a raw date-fns locale objectreturnlocaleSpec;}
Can you think of any reason not to support this?
The text was updated successfully, but these errors were encountered:
whatisaphone
changed the title
Support locales without requiring the global variable
Adding a locale modifies the window object
Mar 8, 2019
We're using react-datepicker in an app where the global context should not be modified. It looks like in v2, non-English locales won't work unless the locales are registered ahead of time on the global
window
object:react-datepicker/src/date_utils.js
Lines 244 to 249 in ad499a2
This does not align with how date-fns itself handles locales. In their docs, they have this example, where the locale object is passed directly as an argument, without going through an indirection layer:
The react-datepicker equivalent would look something like this:
Allowing that usage would let you manage locales with all the flexibility that date-fns itself allows. Supporting it in a backwards-compatible way would (at first glance) require only one change, here, to something like this:
Can you think of any reason not to support this?
The text was updated successfully, but these errors were encountered: