DEV Community

Arooba Zaman
Arooba Zaman

Posted on

πŸš€ React Hooks & Rendering β€” A Clear Mental Model (For My Future Self Too)

πŸͺWhat are React Hooks?
Hooks are helpers that let a function component:
remember data
react to changes

🧠 Core React Hooks (WHAT + WHY)

πŸ”Ή useState β€” data that affects the UI
Why it exists:
React re-runs components often. Without state, values would reset every time.
Use when:
The user should see the change.

πŸ”Ή useEffectβ€” side work after render
Why it exists:
Some work should happen after the UI is painted, not during it.
Used for:
API calls
timers

πŸ”ΉuseRef β€” remember without re-render
Why it exists:
Sometimes React needs to remember something without updating the UI.
Two main uses:
DOM access β†’ focus input, scroll, measure
Silent storage β†’ timer IDs, previous values, flags

πŸ”Ή useContext β€” shared/global data
Why it exists:
To avoid passing props through many layers.
Used for:
logged-in user
theme

πŸ”Ή useMemo β€” avoid heavy recalculations
Why it exists:
React re-runs components often β†’ slow calculations can repeat unnecessarily.
Use when:
calculation is expensive

πŸ”Ή useCallback β€” stable functions
Why it exists:
Functions are recreated on every render.
Used mainly when:
passing callbacks to optimized child components

🌍 Rendering Types (WHY they exist)

πŸ”Ή CSR β€” Client Side Rendering
What: Browser builds the UI
Best for: dashboards, internal tools

πŸ”Ή SSR β€” Server Side Rendering
What: Server sends ready HTML
Why: Search engines need content

πŸ”Ή SSG β€” Static Site Generation
What: Page built once at build time
Why: Some content rarely changes

Hope it helps someone else too

Top comments (0)