Sphere
Log in Join
☆ 8

useEffect runs twice in development, is this a bug?

React 18 StrictMode makes my fetch effect run twice in dev. In production it runs once. I added a cleanup but the request still shows twice in the network tab.

⚑ Report

3 replies

☆ 0
R regexraccoon42 ·2026-10-25#1

StrictMode mounts, unmounts, and remounts components to expose missing cleanup. The first request is real; your cleanup must abort it.

⚑ Report
☆ 0
F fern42 ·2026-10-25#2

I return a function but it only sets a flag and does not cancel fetch.

⚑ Report
☆ 0
S Sofia ·2026-10-26#3

Use an AbortController and call abort() in cleanup. Then the first request is cancelled and you will see only one completed request.

⚑ Report
Log in to reply.