![]() |
VOOZH | about |
React, a declarative and efficient JavaScript library for UI development, focuses on the 'V' (View) in MVC, serving as an open-source, component-based front-end tool maintained by Facebook. The react-day-picker enhances date picking in web apps, featuring the React DayPickerInput component for an input field linked to an overlay displaying the DayPicker.
<DayPicker locale="*" weekdaysLong="*" weekdaysShort="*" months="*" />Step 1: Create a react application using the following command.
npx create-react-app foldernameStep 2: Once it is done, change your directory to the newly created application using the following command.
cd foldernameStep 3: Install the module using the following command:
npm install react-day-picker
npm install moment
Project Structure:
The updated dependencies in package.json file will look like:
"dependencies": {
"react": "^18.2.0",
"react-day-picker": "^8.9.1",
"react-dom": "^18.2.0",
"react-icons": "^4.12.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4",
}
In order to change the language of DatePickerInput, we need to use the dayPickerProp i.e locale. This is known as localization.
Example 1: In this example, we will preDefine Months, weekdays for the language. Then we will render them accordingly.
Step to Run Application: Run the application using the following command from the root directory of the project:
npm startOutput:
Example 2: In this example, we will again have a dropdown menu for selecting Language, and the calendar will render accordingly. This time we don't need to specifically mention weekdays and other props. These are imported using moment, for example, import 'moment/locale/hi' for Hindi language weeks, days, etc.
Step to Run Application: Run the application using the following command from the root directory of the project:
npm startOutput: