React.js render() Method
Last Updated :
11 Sep, 2024
The Render method is a core part of React components and component lifecycle. It is used to describe how the UI should look like.
React.js library is all about splitting the app into several components. Each Component has its own lifecycle. React provides us some in-built methods that we can override at particular stages in the life-cycle of the component.
Render in React
Render method in react is used to define the UI of the web page. It returns UI defined to be displayed in the required structure.
Syntax:
function render() {
return (
<div>
<h1>Hello, {this.props.name}!</h1>
</div>
);
}
This method does not take any props. But it can access the class props using this keyword e.g. this.props.name .
Note: It is only used in react class components, there is no explicit render method in functional components.
In class-based components, the render() method is the only required and most important method of all in-built life-cycle hooks/methods. 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).
Steps to Create React Application
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
Project Structure:
It will look like the following.

Project Structure
Example: This example uses Render method to display data on the Web page.
JavaScript
// Filename - App.js
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 from the root directory of the project, using the following command
npm start
Output:

Summary
The Render method in react class components is used to define the UI of the we page. It is a part of react component lifecycle and is called to define the user inteface in the initial phase.