All writingFrontend

Demystifying React useEffect: A Simple Guide

Oct 05, 2026 · 4 min read

Learn how to manage side effects, dependency arrays, and cleanup functions in React functional components.

The useEffect hook lets you perform side effects in your components, such as fetching data, updating the DOM, or setting up subscriptions.

Understanding the Dependency Array

Cleanup Functions

If your effect sets up a timer or event listener, return a cleanup function to prevent memory leaks when the component unmounts:

useEffect(() => {
  const timer = setInterval(() => console.log('Tick'), 1000);
  return () => clearInterval(timer); // Cleanup
}, []);