useRef, useMemo, useCallback and Friends
Learn useRef, useMemo, useCallback and Friends (Phase 6 · React Hooks (Essential), ReactJS) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
useRef: values that do not trigger renders • const ref = useRef(initial) gives a stable object { current } that persists across renders. Changing ref.current does not re-render. • Two uses: (1) reach a DOM node ( <input ref={ref} /> then ref.current.focus() ), (2) hold mutable values that are not part of the UI (timer ids, previous value, latest callback). • Never read or write ref.current during render (except to initialise).