title: ReactJS - wait for cookie to load before running function?
body: <p>I have a React App that straight away (on load), checks to see if there is a cookie, then if there is a cookie, it performs a function etc.</p>
  
  <p>But the app will be loaded up from a Redirect</p>
  
  <p><a href="https://i.stack.imgur.com/VpGce.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VpGce.png" alt="enter image description here"></a></p>
  
  <p>This is the code so far:</p>
  
  <pre><code>export class Landing extends Component {
      constructor(props) {
          super(props);
          this.state = {};
      }
  
      componentDidMount() {
          function onLoad(props) {
  
              const cookieValue = Cookies.get("cookieJWT");
  
              if(cookieValue){
                 console.log(cookieJWT);
              } else { console.log('No cookie found!') }
          }
  
          onLoad();
     }
  }
  
  </code></pre>
  
  <p>The problem is, the onLoad() function runs so quick before the cookie from redirect is ready, so  returns as not there!</p>
  
  <p>I have tried to use componentDidMount(), but think I need to use async and await, but how do I do this so it waits for cookie to load/redirect to finish properly?</p>
  
  <p>Thanks in advance :)</p>