title: React custom Hook using useRef returns null for the first time the calling component Loads?
body: <p>I have created a custom hook to scroll the element back into view when the component is scrolled. </p>
  
  <pre><code>export const useComponentIntoView = () =&gt; {
    const ref = useRef();
    const {current} = ref;
    if (current) {
      window.scrollTo(0, current.offsetTop );
    }
    return ref;
  }
  </code></pre>
  
  <p>Now i am making use of this in a functional component like </p>
  
  <pre><code>&lt;div ref={useComponentIntoView()}&gt;
  </code></pre>
  
  <p>So for the first time the current always comes null, i understand that the component is still not mounted so the value is null . but what can we do to get this values always in my custom hook as only for the first navigation the component scroll doesn't work . Is there any work around to this problem . </p>