The Mental Model Shift
You'll learn: How Hooks change the way you think about React from lifecycle events to synchronization.
From Lifecycle Thinking to Synchronization Thinking
With class components, you think in terms of when things happen: "When the component mounts, fetch data. When props change, do something. When it unmounts, clean up." You're constantly asking yourself which lifecycle method to use.
With Hooks, you shift to thinking about keeping things in sync: "This effect should run after every render where these dependencies changed. This state should reflect this prop. This subscription should stay active as long as the component exists."
The Key Difference
Class lifecycle mental model:
- "I need to do X when the component mounts" →
componentDidMount - "I need to do Y when this prop changes" →
componentDidUpdate+ comparison logic - "I need to cleanup Z when unmounting" →
componentWillUnmount
Hooks mental model:
- "I need to keep the component synchronized with this external system" → One effect that runs after render
- "This logic should happen whenever these values change" → Dependencies array
- "Cleanup belongs with setup" → Return cleanup from the same effect
An Analogy
Class lifecycles are like having separate TODO lists for "morning tasks," "when the weather changes tasks," and "bedtime tasks." You manage three lists and remember which task goes where.
Hooks are like having one smart assistant per concern: "Keep the room temperature comfortable" (it checks when needed and adjusts automatically). Each assistant handles its own setup and cleanup together.
Key Takeaway: Stop thinking "which lifecycle method do I use?" and start thinking "what am I trying to keep synchronized, and what does it depend on?"