Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When the ref callback argument is NULL in react?

Tags:

reactjs

In some component when I use ref callback to receive component's ref, the argument of callback is null. When and in what situations the argument will be null?

like image 450
zerob4wl Avatar asked Sep 13 '25 15:09

zerob4wl


1 Answers

React will call the ref callback with the DOM element when the component mounts, and call it with null when it unmounts.

https://reactjs.org/docs/refs-and-the-dom.html#callback-refs

like image 97
Jonathan.Brink Avatar answered Sep 16 '25 12:09

Jonathan.Brink