Skip to main content

useEffect: Side Effects, Dependencies and Cleanup

Learn useEffect: Side Effects, Dependencies and Cleanup (Phase 6 · React Hooks (Essential), ReactJS) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Synchronising with the outside world • An effect runs after React has rendered and committed to the DOM. Use it for things outside React: network requests, subscriptions, timers, manual DOM work, document.title , third-party widgets. • useEffect(setup, deps) : with [] it runs once after mount; with [a, b] after mount and whenever a or b change; with no array after every render. • Return a cleanup function; it runs before the effect re-runs and on unmount.

More lessons in Phase 6 · React Hooks (Essential)