How to create Calendar in ReactJS ?
Last Updated :
26 Jul, 2024
Creating a calendar in React JS can help in React projects like to-do lists, e-commerce sites, Ticket booking sites, and many more apps. It visualizes the day, month, and year data and makes an interacting User interface.
Prerequisites
To create a calendar in React JS we will be using these approaches
Steps to create React Application
Step 1: You can create a new ReactJs project using the below command:
npx create-react-app gfg
Project Structure

Approach 1: Using @natscale/react-calendar
we are going to create a very simple calendar without any styling. So for this, we are going to install a new npm package. Run the below code in your terminal to install the package.
npm i @natscale/react-calendar
The updated dependencies in package.json will look like
{
"dependencies": {
"@natscale/react-calendar": "^0.0.0-beta.26",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
}
Example: Import and use the calender component from the installed library with useState variable to store values.
JavaScript
// Filename - App.js
import React, { useState, useCallback } from "react";
import { Calendar } from "@natscale/react-calendar";
export default function CalendarGfg() {
const [value, setValue] = useState();
const onChange = useCallback(
(value) => {
setValue(value);
},
[setValue]
);
return (
<div>
<h1>Calendar - GeeksforGeeks</h1>
<Calendar value={value} onChange={onChange} />
</div>
);
}
Steps to run the application: Run the below command in the terminal to run the app.
npm start
Output: This output will be visible on the http://localhost:3000/ on the browser window.
Approach 2: Using react-calendar
Using React-calender we can create a calender with some basic stylings. Run below command to install the react-calender package.
npm i react-calendar
The updated dependencies in package.json will look like
{
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-calendar": "^4.6.1",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
}
Example: Create a Calender with importing some basic styling provided by the library.
JavaScript
import React, { useState } from 'react';
import Calendar from 'react-calendar';
import 'react-calendar/dist/Calendar.css';
export default function CalendarGfg() {
const [value, onChange] = useState(new Date());
return (
<div>
<h1>Calendar - GeeksforGeeks</h1>
<Calendar
onChange={onChange}
value={value}
/>
</div>
);
}
Steps to run the application: Run the below command in the terminal to run the app.
npm start
Output: This output will be visible on the http://localhost:3000/ on the browser window.
Similar Reads
How to Create Calendar App in React Native ?
In this article, we will see how to add a Calendar in React Native App. Discover how to enhance your React Native application by integrating a calendar using the powerful react-native-calendars library. With React Native's ability to facilitate cross-platform mobile app development using JavaScript.
2 min read
How to create components in ReactJS ?
Components in React JS is are the core of building React applications. Components are the building blocks that contains UI elements and logic, making the development process easier and reusable. In this article we will see how we can create components in React JS. Table of Content React Functional C
3 min read
How To Create a Website in ReactJS?
ReactJS is one of the most popular JavaScript libraries for building user interfaces. It allows you to create dynamic, reusable UI components and efficiently manage state and events. In this article, we'll walk through the steps to create a basic website using ReactJS. PrerequisitesNPM & Node.js
5 min read
How to create an event in React ?
In the development of contemporary webpages, user interactions play a pivotal role. These interactions include mouse clicks, keypresses, or even uncommon events like connecting a battery to a charger. As developers, our task is to actively "listen" to these events and subsequently ensure that our ap
2 min read
How to create Class Component in React?
JavaScript syntax extension permits HTML-like code within JavaScript files, commonly used in React for defining component structure. It simplifies DOM element manipulation by closely resembling HTML syntax. JSX facilitates the creation of reusable UI building blocks, defined as JavaScript functions
2 min read
How are forms created in ReactJS ?
Form is a document that stores information of a user on a web server using interactive controls. A form contains different kinds of information such as username, password, contact number, email ID, etc. Creating a form in React is almost similar to that of HTML if we keep it simple and just make a s
3 min read
How to create Dialog Box in ReactJS?
In modern web development, creating interactive and user-friendly interfaces is essential. One common element found in many applications is a dialog box. A dialog box is a component that appears on top of the main content to display information, receive user input, or prompt for confirmation. In thi
2 min read
How to create Dialog Box in ReactJS?
Dialogs inform users about a task and can contain critical information, require decisions, or involve multiple tasks. Material UI for React has this component available for us and it is very easy to integrate. We can create the dialog box in ReactJS using the following approach: Creating React Appli
2 min read
How to create Menu Item Component in ReactJS ?
React JS is a popular JavaScript library used for building user interfaces. It provides a component-based architecture that allows developers to create reusable UI elements. Material UI for React has this component available for us and it is very easy to integrate. We can use Menu Component in React
2 min read
How to create a Dictionary App in ReactJS ?
In this article, we will be building a very simple Dictionary app with the help of an API. This is a perfect project for beginners as it will teach you how to fetch information from an API and display it and some basics of how React actually works. Also, we will learn about how to use React icons. L
4 min read