Pak RT’s puppet chest: every gong strike re-renders <Lakon />, and every function and object carries its identity number, so you see when useCallback, useMemo…
Why it matters
Misreading it breeds two bugs: memo sprinkled everywhere (noisy code, no gain) and props never made stable (React.memo and effect deps never work). Understanding reference equality makes optimisation land where it should.
The key idea
Memo only works when its props are stable by reference
Common mistakes
Wrapping EVERYTHING in useMemo/useCallback Memo itself costs memory and time comparing deps. For cheap values it costs more than computing again. Use it when passing props to a memoized child, when it is an effect’s dependency, or when the calculation really is heavy.
useCallback but the child has no memo Without React.memo on the child, a stable reference does nothing: the child still renders with its parent. It takes both.
A value from useMemo does not change, it looks staleuseMemo(() => 'Lakon: ' + judul, []) uses judul but its deps are empty: the result goes stale. Just like useEffect, the deps must be complete.
Try it in this playground
Strike the gong with onSapa = () => {} Semar (memo) still renders: the function is new every render.
Switch to useCallback, strike again Semar stays still: onSapa keeps the same number, === true.
Strike the gong with gaya = { … } Equal contents are not enough: Petruk (memo) renders because the object is new.
Turn React.memo off Everyone renders, whatever the props: stable references alone do not help.