Hacker0x01 / react-datepicker

A simple and reusable datepicker component for React
https://reactdatepicker.com/
MIT License
7.9k stars 2.23k forks source link

Setting attribute locale={"en-US"} throws 391-395 console warnings #3781

Open n-glaz opened 1 year ago

n-glaz commented 1 year ago

Describe the bug Setting ReactDatePicker's locale attribute to 'en-US' or "en-US" causes 395 warnings to be thrown in the console when the datepicker is interacted with.

Dates still appear to be displayed properly as per the locale.

To Reproduce

import ReactDatePicker from "react-datepicker";

export const PageWithDatepicker = () => {
    <>
        <ReactDatePicker
            locale={'en-US'}
            placeholderText="Select date"
         />
    </>
}

Expected behavior

I expect to not get 395 console errors when setting the locale attribute to 'en-US'.

Screenshots

Screen Shot 2022-09-29 at 4 23 34 PM

Desktop (please complete the following information):

fedemp commented 1 year ago

According to the README, you have to import the corresponding locales from date-fns.

import { useState } from "react";
import { createRoot } from "react-dom/client";
import DatePicker, { registerLocale } from "react-datepicker";
import es from 'date-fns/locale/en-US';
registerLocale('en-US', es)
import "react-datepicker/dist/react-datepicker.css";

// CSS Modules, react-datepicker-cssmodules.css
// import 'react-datepicker/dist/react-datepicker-cssmodules.css';

const Example = (): JSX.Element => {
  const [startDate, setStartDate] = useState(new Date());
  return (
    <DatePicker
      locale="en-US"
      selected={startDate}
      onChange={(date) => date && setStartDate(date)}
    />
  );
};

const container = document.querySelector("#app")!;
const root = createRoot(container);

root.render(<Example />);
github-actions[bot] commented 1 month ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 10 days.