When should you NOT use useEffect?

React hooks and effects · Freshers and experienced

Model answer

Not for calculating values from props or state (do it during render), not for responding to a user event (put the logic in the event handler), and not for resetting state when a prop changes (use a key). Effects are for synchronising with external systems.

Overusing effects causes extra renders and tangled logic. The official guide "You Might Not Need an Effect" explains this well.

Learn this topic

React useEffect Explained: Side Effects, Dependencies and Cleanup in the course React.js Full Course: Beginner to Advanced.

Sign in to add your own answer.

More questions