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>
);
}
export default App;
Output:
Count: 13
Click MeTry clicking the button. The count changes because React re-renders the component.
Step-by-step:
Top comments (0)