DEV Community

Amal Amr Zewita
Amal Amr Zewita

Posted on

What is useEffect in React?

useEffect is a built-in React Hook that lets you run code after the component renders.

It’s commonly used for:

  • Fetching data from APIs
  • Setting up subscriptions
  • Updating the DOM
  • Cleaning up on unmount

🧠 Basic Example


tsx
import { useEffect } from 'react';

useEffect(() => {
  console.log("Component mounted!");
}, []);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)