I was doing a code review and found the code written by another developer such as:
function sampleComponent() {
let divRef = {};
return (
<div ref={(el) => { divRef = el }}></div>
)
}
And then use the divRef as a reference to DOM element.
However, the pattern that I know is using createRef in class component and useRef hook in functional component. Even the ReactJS official https://reactjs.org/docs/refs-and-the-dom.html said to avoid inline ref for future React version. Is it a legacy pattern to write?
So far what I can research is, inline ref will render the function two times, therefore it is recommended to avoid.
I was wondering what are the other explanation available for this?