ReactuseEffect Hook

useEffect is a React Hook that lets you perform side effects in function components. It's commonly used for fetching data, setting up subscriptions, or manually changing the DOM.

import React, { useState, useEffect } from 'react';

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

  useEffect(() => {
    const interval = setInterval(() => {
      setCount((prev) => prev + 1);
    }, 1000);

    return () => clearInterval(interval);
  }, []);

  return <h2>Timer: {count}</h2>;
}