Explain the purpose of render() in ReactJS Last Updated : 09 Jan, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Render in React JS is a fundamental part of class components. It is used to display the component on the UI returned as HTML or JSX components. The ReactDOM.render() function takes two arguments, HTML code and an HTML element.Purpose of render()React renders HTML to the web page by using a function called render().The purpose of the function is to display the specified HTML code inside the specified HTML element.In the render() method, we can read props and state and return our JSX code to the root component of our app.In the render() method, we cannot change the state, and we cannot cause side effects( such as making an HTTP request to the webserver).Let's understand the render function with an example.Steps to create React ApplicationStep 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 foldernameProject Structure:Example: Render funtion display the html on the UI as given in App.js file. JavaScript import React, { Component } from "react"; export default class App extends Component { state = { PawriDays: [ { id: "123s", Day: "Monday" }, { id: "234r", Day: "Saturday" }, { id: "12d5", Day: "Sunday" }, ], }; render() { const PartyDays = this.state.PawriDays.length; const style = { textAlign: "center", color: "green", }; // Return JSX code return ( <div style={style}> <h1>I am User</h1> <p> We party: {PartyDays} days a week </p> </div> ); } } Step to Run Application: Run the application using the following command from the root directory of the projectnpm startOutput: Now open your browser and go to http://localhost:3000/, you will see the following output Comment More infoAdvertise with us Next Article ReactJS Render Props A akshitsaxenaa09 Follow Improve Article Tags : Web Technologies ReactJS Blogathon Blogathon-2021 React-Questions +1 More Similar Reads Explain the concept of Redux in React. Redux is a state management library commonly used with React, although it can also be used with other JavaScript frameworks. It helps manage the state of your application. It was inspired by Flux, another state management architecture developed by Facebook for building client-side web applications. 3 min read ReactJS Render Props Render Props is a React pattern that allows components to share logic by passing a function as a prop. The receiving component calls this function to render content dynamically, enabling code reuse while keeping the UI flexible.Syntaxconst DataProvider = ({ render }) => render("Hello, Render Prop 4 min read What is the purpose of the onClick event in React? The onClick event plays an important role for enhancing user interactions with components in react applications which allows developers/programmers to call a function or method that gets executed when a particular element is clicked. Whether triggering a state change, navigating to another page, or 4 min read Re-rendering Components in ReactJS Re-rendering is an important concept in ReactJS as it determines how and when components update. Understanding the re-rendering process is essential for optimizing the performance of React applications.What is Re-rendering in ReactJS?In React, a re-render happens when a component's state or props ch 5 min read Explain StaticRouter in React Router React Router is a powerful library for handling routing in React applications, allowing developers to create dynamic single-page applications (SPAs) with ease. While the BrowserRouter is commonly used for client-side routing in web applications, there are scenarios where server-side rendering (SSR) 4 min read Destructuring of Props in ReactJS Destructuring is a simple property that is used to make code much clear and readable, mainly when we pass props in React.Table of ContentWhat is Destructuring?Advantages of DestructuringHow to use Destructuring?Using this.props methodUsing the Extraction methodUsing the Re-assigning methodSummaryWha 4 min read Like