VOOZH about

URL: https://www.geeksforgeeks.org/reactjs/how-to-use-collapse-component-in-reactjs/

⇱ How to use Collapse Component in ReactJS ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to use Collapse Component in ReactJS ?

Last Updated : 23 Jul, 2025

ReactJS, a popular JavaScript library for building user interfaces, provides developers with a rich set of components to create interactive and dynamic web applications. One such component is the Collapse component, which allows you to hide and reveal content based on user interaction. In this article, we will explore how to effectively use the Collapse component in ReactJS to create collapsible sections within your applications.

Prerequisites

Steps to create React Application And Installing Module:

Step 1: Create a React application using the following command.

npx create-react-app foldername

Step 2: After creating your project folder i.e. foldername, move to it using the following command.

cd foldername

Step 3: After creating the ReactJS application, Install the material-ui modules using the following command.

npm install @material-ui/core

Project Structure: 

👁 Image
Project Structure

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code. 

Step to Run Application: Run the application using the following command from the root directory of the project.

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output.

Reference:https://mui.com/material-ui/transitions/#collapse

Comment
Article Tags: