A stable value keeps the same identity across component renders. It can be omitted from a hook dependency array when its reference is known never to change. This matters especially for functions and objects: identical behavior or structure does not guarantee identical identity. section 3.3.3
Common stable values include:
- Constants defined outside a component or imported from another file. section 3.3.3
- The setter returned by useState, whose function reference remains stable even when the state value changes. section 3.3.3
- The object returned by useRef, whose identity remains stable while its current property remains dynamic. section 3.3.3
const [items, setItems] = useState(["Clean gutter", "Do dishes"]);
...
const onDelete = useCallback(
(item) => setItems( #1
(list) => list.filter((i) => i !== item),
),
[] #2
);
Shows useCallback omitting the stable useState setter from its dependency array. section 3.3.3
