The Three Lifecycle Phases: Mount, Update, Unmount
What you'll learn: Every class component goes through three distinct stages during its life, and React provides special methods that run during each phase.
The Component Lifecycle
Think of a class component like a light bulb. It gets installed (mount), it might flicker or change brightness (update), and eventually it gets removed (unmount). React components follow this same pattern, and understanding these phases is key to working with class components.
The Three Phases
Mount happens when a component first appears on the screen. React creates the instance, runs the constructor(), and calls render() for the first time. This is your component's "birth."
Update occurs whenever props or state change. React re-runs render() to reflect the new data. This phase can happen many times—or never—depending on how your component is used. It's the component's "life."
Unmount is when React removes the component from the screen entirely. This is your last chance to clean up—like canceling timers or closing connections. It's the component's "death."
Why This Matters
Each phase has specific lifecycle methods that run automatically. During mount, you might fetch data. During update, you might compare old and new props. During unmount, you might clean up subscriptions.
Understanding these phases helps you predict when your code runs. The constructor() you learned earlier? That's a mount-only method. setState() calls? Those trigger updates. And there are methods specifically for unmount cleanup (though you'll learn those details later).
Key Takeaway: Every class component lives through three phases—Mount (birth), Update (changes), and Unmount (removal)—and React provides lifecycle methods that run during each phase, giving you control over what happens when.