Lifecycle
ELI5 — The Vibe Check
The lifecycle is a component's life story — it's born (mounted), lives and updates (updates), then dies (unmounted). Frameworks give you hooks into these moments so you can run code at the right time, like fetching data when the component appears on screen.
Real Talk
Component lifecycle refers to the sequence of phases a component goes through: creation, mounting to the DOM, updating on state/prop changes, and unmounting. Lifecycle hooks let you execute code at specific phases — e.g., onMounted for initial data fetching or onUnmounted for cleanup.
Show Me The Code
// Vue Composition API
import { onMounted, onUnmounted } from 'vue';
onMounted(() => {
console.log('Component is live!');
startPolling();
});
onUnmounted(() => {
stopPolling();
});
When You'll Hear This
"Fetch the data in the mounted lifecycle hook, not in the template." / "Clean up your event listeners in onUnmounted or you'll get memory leaks."
Related Terms
Component
A component is a self-contained LEGO brick for your UI.
Composable
Composables are Vue's version of React hooks — reusable functions that bundle reactive state and logic together.
Hook
Hooks are special functions in React that let function components use superpowers like state and lifecycle that used to be class-only.
Hydration
Hydration is when a server-rendered HTML page comes alive in the browser.
State
State is a component's memory — data that can change over time and causes the UI to update when it does. Think of a counter: the number is state.