title: How can we use a value from component state while exporting in react
body: <p>my class component is like this:</p>
  <pre class="lang-js prettyprint-override"><code>import React, { Component } from &quot;react&quot;;
  
  let EXPORT_TITLE = &quot;&quot;;
  
  class EditCook extends Component {
    state = {
      title: &quot;page title&quot;
    };
  
    render() {
  
      EXPORT_TITLE = this.state.title; // &lt;---------- Here I am setting the value of the global variable
  
      return &lt;div&gt;SOME JSX&lt;/div&gt;;
    }
  }
  
  console.log(EXPORT_TITLE); // &lt;--------- I want to access the value from components state here. 
  
  export default EditCook;
  </code></pre>
  <p>I want to access the <strong>value</strong> of <strong>title</strong> from the components state outside the component.
  The actual use case is that I have a Higher order component where I need to send the title of the page while exporting like this.</p>
  <pre class="lang-js prettyprint-override"><code>export default withPageSpec(EditCook, {
    title: EXPORT_TITLE,
  });
  
  </code></pre>
  <p><a href="https://codesandbox.io/s/nervous-rgb-vvpem?file=/src/App.js" rel="nofollow noreferrer">Here is the codesandbox link for the above</a></p>