Mounting is the first phase of a React component's lifecycle.
When a component is created and displayed on the screen for the first time, it is called Mounting.
- Mounting steps
- Component Function Runs – React executes the component.
- DOM Creation – React prepares the UI.
- DOM Update – React displays the UI on the screen.
- useEffect Runs – The effect runs after the component is displayed.
Example:
import React, { useEffect } from 'react';
function App() {
useEffect(() => {
console.log("Component Mounted");
}, []);
return (
<h1>Hello React!</h1>
);
}
export default App;
Output:
Hello React!
Console:
Component Mounted
Top comments (0)