in doc https://reactjs.org/docs/hooks-faq.html#how-can-i-measure-a-dom-node part "How to read an often-changing value from useCallback?" there is an example: