Chapter 8 · Example 4 · React Context and performance

Memoizing the value

Wrapping the provider value in useMemo and the toggle in useCallback keeps the reference stable, so consumers stop re-rendering when the parent re-renders.

Loading live editor…