Exception: External System Synchronization
What you'll learn: When useEffect is actually the right tool—syncing React with non-React systems that live outside your component tree.
The One Valid Reason to Use useEffect
We've spent many lessons learning what not to do with useEffect—don't derive state, don't transform props, don't trigger chains of updates. But there's one scenario where useEffect is exactly right: connecting React to external systems.
What Counts as an External System?
External systems are anything that exists outside React's control:
- Browser APIs (timers, geolocation, media players)
- Third-party libraries (maps, analytics, chat widgets)
- WebSocket connections
- DOM measurements or imperative DOM operations
- Global event listeners (scroll, resize, keyboard)
These systems don't "speak React." They don't know about renders, state, or props. useEffect is the bridge that keeps them in sync with your component's lifecycle.
The Pattern
When you need to:
- Start something when the component mounts or dependencies change
- Stop or clean it up when dependencies change or the component unmounts
Then useEffect is correct. You're not deriving from React values—you're coordinating with the outside world.
The Key Difference
- ❌ Wrong: Using
useEffectto computefilteredListfromlistprop - ✅ Right: Using
useEffectto start asetIntervaltimer - ❌ Wrong: Using
useEffectto setfullNamefromfirstName+lastName - ✅ Right: Using
useEffectto connect to a WebSocket and listen for messages
Key Takeaway: useEffect is for synchronization with external systems, not for transforming React values. If your effect just sets state based on other state or props, you're probably doing it wrong—but if you're managing a timer, subscription, or third-party library, you're using it correctly.