Tsallaka zuwa abun ciki
Justice Tech School

The useEffect Hook

useEffect runs code after render to sync with outside systems such as timers, subscriptions or the network. The dependency array says when to re-run.

Example
import { useEffect } from 'react';

function Title({ text }) {
  useEffect(() => {
    document.title = text;
  }, [text]);
  return null;
}

Exercise

Run once on mount.

useEffect(fn, )

Quiz Test

When does an effect with [] run?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.