Class components have lifecycle methods such as:

  • componentDidMount() – Runs after the component is rendered.
  • componentDidUpdate() – Runs when component updates.
  • componentWillUnmount() – Runs before component is removed.

Functional components use hooks like useEffect().

import { useEffect } from 'react';
function Example() {
  useEffect(() => {
    console.log("Component Mounted");
    return () => console.log("Component Unmounted");
  }, []);
  return <h1>Hello!</h1>;
}