How to use Portal Component in ReactJS ? Last Updated : 23 Jul, 2024 Comments Improve Suggest changes Like Article Like Report The portal component renders its children into a new subtree outside the current DOM hierarchy. Material UI for React has this component available for us, and it is very easy to integrate. We can use the Portal Component in ReactJS using the following approach.Prerequisites:NodeJS or NPMReact JSMaterial UISteps to Create the React Application And Installing Module:Step 1: Create a React application using the following command.npx create-react-app foldernameStep 2: After creating your project folder i.e. foldername, move to it using the following command.cd foldernameStep 3: After creating the ReactJS application, Install the material-ui modules using the following command.npm install @material-ui/coreProject Structure:Project StructureThe updated dependencies in package.json file will look like:"dependencies": { "@material-ui/core": "^4.12.4", "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "5.0.1", "web-vitals": "^2.1.4",}Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code. JavaScript import React from 'react'; import Portal from '@material-ui/core/Portal'; export default function App() { const [isVisible, setVisibility] = React.useState(false); const box = React.useRef(null); return ( <div style={{ display: 'block', padding: 30, width: 500 }}> <h4>How to use Portal Component in ReactJS?</h4> <button type="button" onClick={() => { setVisibility(!isVisible) }}> {!isVisible ? 'Mount the Children' : 'Unmount the Children'} </button> <div style={{ padding: 12, margin: 2, border: '2px solid', }}> Greetings from GeeksforGeeks {isVisible ? ( <Portal container={box.current}> <span>Your Mounted Data is Here!!</span> </Portal> ) : null} </div> <div style={{ padding: 12, margin: 2, border: '2px solid', }} ref={box} /> </div> ); } Step to Run Application: Run the application using the following command from the root directory of the project.npm startOutput: Now open your browser and go to http://localhost:3000 Comment More infoAdvertise with us Next Article How to use Portal Component in ReactJS ? gouravhammad Follow Improve Article Tags : JavaScript Web Technologies ReactJS React-Questions Similar Reads How to use Pagination Component in ReactJS ? Pagination is a feature through which users can easily switch between pages across a website or app. With the help of this component, a user can select a specific page from a range of pages. Material UI for React has this component available for us, and it is very easy to integrate. We can use the f 2 min read How to use Link Component in React JS? Material-UI provides a set of components that can be seamlessly integrated with React to create visually appealing and functional navigation elements. The Link component allows you to easily customize anchor elements with our own theme colors and typography styles. Material UI for React has this com 2 min read How to use DataGrid Component in ReactJS ? A DataGrid Component helps in displaying the information in a grid-like format of rows and columns. Material UI for React has this component available for us, and it is very easy to integrate. We can use the following approach in ReactJS to use DataGrid Component.Creating React Application And Insta 2 min read React Suite Portal Component React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. Portal component renders its children into a new subtree outside the current DOM hierarchy. We can use the following approach in ReactJS to use the React Suite P 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 ReactJS Evergreen Portal Component React Evergreen is a popular front-end library with a set of React components for building beautiful products as this library is flexible, sensible defaults, and User friendly. Portal Component provides a way for the user to render outside the current DOM tree. It is a simple utility component that 2 min read Link Component in React Router React Router is a powerful library in ReactJS that is used to create SPA (single-page applications) seamlessly. One of the components of the React Router is Link. In this article, we will be seeing the working of the Link component, various props, and usage of the Link component within React Router 5 min read ReactJS Blueprint Portal Component BlueprintJS is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex data-dense for desktop applications. Portal Component renders its children into a new subtree outside the current component hierarchy. We can use the following app 2 min read Navigate Component in React Router In React applications, navigation between different pages or views is an essential part of creating dynamic user interfaces. React Router is a popular library used for handling routing and navigation. One of the key features of React Router is the Navigate component, which allows for programmatic re 7 min read Route Component in React Router React Router is a popular library used for managing routing in React applications. At its core lies the Route component, which plays a pivotal role in defining the relationship between URLs and corresponding components. In this article, we'll delve into the intricacies of the Route component, explor 5 min read Like