React · Senior · Question 26 of 75

What's new about callback refs in React 19?

Explanation

<div ref={node => { const obs = observe(node); return () => obs.disconnect(); }}> - the cleanup runs when the element is removed or the callback changes. Previously React called the callback with null, and cleanup had to be written by hand.

Further reading

Problem with a question

React · Senior · question 26

Test yourself

Take the React · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz