title: Export variable from componentDidMount
body: <p>How do I export the "x" variable from componentDidMount so i can use it in the render section? I am trying to check for the x position of my div.</p>
  
  <pre><code>import React from 'react';
  
  class Icon extends React.Component {
    constructor(props) {
      super(props);
      this.selector = React.createRef();
    }
  
    componentDidMount = () =&gt; {
      var rect = this.selector.current.getBoundingClientRect();
      var x = rect.top;
      console.log(x);
     };
  
    render() {
      return (
        &lt;div className="icon" ref={this.selector}&gt;
          &lt;p&gt;x: {x} &amp; y:&lt;/p&gt;
        &lt;/div&gt;
      );
    }
  }
  
  export default Icon;
  </code></pre>