Skip to main content

Effects visual mental model

Before memorising useEffect, classify the work.

Render, event, or Effect?Choose by cause, not by timing.
RenderCalculate UI

Pure calculations from current props, state, and context.

EventRespond to intent

Work caused by a specific click, submit, drag, or other interaction.

EffectSynchronize externally

Keep React aligned with a browser API, subscription, timer, connection, or third-party system.

The synchronization lifecycleโ€‹

An Effect is better understood as a process that can start and stop repeatedly.

Effect lifecycleThink setup โ†’ cleanup โ†’ setup, not mount/update/unmount.
1Render with room = general
2Connect to general
3room changes to travel
4Disconnect general
5Connect travel
6Component leaves
7Disconnect travel

Dependencies configure the processโ€‹

Dependencies are not a scheduling wish list
Effect reads reactive values

Example: roomId and serverUrl.

Dependency list describes them

[roomId, serverUrl]

React re-synchronizes

Cleanup the old process, then start the new one.

Cleanup mirrors setupโ€‹

Correct Effect symmetry
Setup

connect ยท subscribe ยท add listener ยท start timer ยท create widget

Cleanup

disconnect ยท unsubscribe ยท remove listener ยท clear timer ยท destroy widget

Should this be an Effect?โ€‹

What caused this work?
Needed to calculate JSX?Render logic
Specific user interaction?Event handler
External system must stay synchronized?Effect
Derived value from existing state?Calculate during render
Parent should own the value?Lift state instead of syncing copies

Strict Mode is a cleanup testโ€‹

Development Strict Mode stress test
Setup
Cleanup
Setup again

If that sequence breaks the integration, the Effect usually has a cleanup or ownership problem. The goal is not to suppress the second setup; the goal is to make the process safe to restart.

Network race mental modelโ€‹

Why stale requests need cancellation or ownership
Request A: react

Starts first, finishes later.

Request B: redux

Starts second, finishes first.

Stale A can overwrite newer B

Use cancellation, framework data APIs, or a server-state library where appropriate.

Keep this picture in your headโ€‹

Effect decision summary
Render
calculate
Event
respond
Effect
synchronize
Cleanup
undo synchronization

Continue with useEffect and Synchronizing with External Systems for the complete API, code examples, debugging cases, and production guidance.