title: TypeError: ref.current is undefined (useRef())
body: <p>I have an image and I want to store its dimensions, for placing icons depending of the dimensions. I do so with useRef() hook.</p>
  
  <pre><code>const componentRef=useRef()
  </code></pre>
  
  <p>Then I add this <code>componentRef</code> to the <code>&lt;img ref={componentRef}&gt;</code>. For rendering the icons, I call a function <code>{setIcons}</code>.</p>
  
  <pre><code>return(
    &lt;div&gt;
      &lt;img ref={componentRef}/&gt;
      {setIcons}
    &lt;/div&gt;
  )
  </code></pre>
  
  <p>This function again looks like this.</p>
  
  <pre><code>const setIcons=(
          props.positions_Reader.map((mac,i)=&gt;(
              &lt;Icon
                  style={{
                    position:"absolute",
                    left:componentRef.current.getBoundingClientRect().x,
                    top:componentRef.current.getBoundingClientRect().y
                  }}
              /&gt;
          ))
      )
  </code></pre>
  
  <p>The error occurs in this line <code>left:componentRef.current.getBoundingClientRect().x</code></p>
  
  <p>At the first render there is no error, but when I go back and open the component again, this error occurs. Are there any suggestions?</p>