📊 We use cookies & analytics to improve your experience. Learn more
Latest

React & Modern Front-End Development Module 2 · Lesson 5 of 15

0% Exit to course

Module 2 · State, effects and live data Lesson 5 of 15

useEffect and fetching an API

Learning objective

An effect runs after render, which is where fetching belongs. The empty dependency array means "once when the component appears" — and the cleanup function is what stops a request from writing into a screen that is gone.

Worked example

A fetch inside useEffect with an array dependency of [] loads once. Dropping the array reloads on every render, which is how a free API quota disappears in two minutes.

Your practice task

Fetch a public list of jobs or films, render it, and add a search box that filters what you already have instead of refetching.

Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.

Key takeaway

An effect runs after render, which is where fetching belongs. The empty dependency array means "once when the component appears" — and the cleanup function is what stops a request from writing into a screen that is gone.

Create free account or sign in

Almost there

15 lessons left of 15

Finish every lesson to unlock the certificate. Each one ends in a practice task — do them and the final project brief writes itself.

Next recommended course Full-Stack Web Development Bootcamp