DEV Community

SATHISHKUMAR R
SATHISHKUMAR R

Posted on

What is Rendering in React?

Rendering means displaying the UI (User Interface) based on the component's JSX.
Rendering means React prepares what should appear on the screen.

Example of Rendering:

function App() {
return (


Hello React!


Welcome to my website.



);
}

export default App;

Output:

Hello React!
Welcome to my website.

React renders this JSX and displays it in the browser.

When does Rendering happen?

There are two main situations:

Initial Render: When a component appears on the screen for the first time.

Re-render: When state or props change and React needs to update the UI.

Example Using useState:

import { useState } from 'react';

function App() {

const [count, setCount] = useState(0);

return (
    <div>
        <h1>Count: {count}</h1>

        <button onClick={() => setCount(count + 1)}>
            Click Me
        </button>
    </div>
);
Enter fullscreen mode Exit fullscreen mode

}

export default App;

Output:

Count: 13

Click MeTry clicking the button. The count changes because React re-renders the component.

Step-by-step:

Initially, count = 0.

React renders the component.

You click the button.

setCount() updates the state.

React renders the component again.

Updated count appears on the screen.

Top comments (0)