The useRef pattern seem like a code smell, maybe because I had some troubles with refs over the years.
Things were simpler when we had lifecycle methods to manage some of this things. But I`m sure that the next version of react will change everything and make us come up with more patters to try to fix the same problem again...