Skip to main content

Hooks: useEffect, useMemo, useRef and Custom Hooks

Learn Hooks: useEffect, useMemo, useRef and Custom Hooks (Phase 15 · React (Essential for your chosen stack), JavaScript) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

useEffect: synchronising with the outside world • useEffect(fn, deps) runs after render . With [] it runs once after mount; with [a, b] it re-runs when a or b change; with no array it runs after every render. • Return a cleanup function to remove listeners, clear timers or abort requests; it runs before the next effect and on unmount. • Typical uses: fetching data, subscriptions, timers, document title. Do not use effects to compute values from props/state: compute them during render.

More lessons in Phase 15 · React (Essential for your chosen stack)