React DOM

Callback ref cleanup

React 19+ supports returning a cleanup function for each attachment; React 18 uses a null callback on detach.

Formal Syntax & Structure

react syntaxreact
ref={node => { if (node) return attach(node); }}

Working Example

Example Snippetreact
return () => node.removeEventListener("focus", onFocus);
React Reference