react redux async load FB javascript sdk
<p>I have a function which loads javascript sdk which is like :</p>

<pre><code>class Facebook{
    constructor(){
        window.fbAsyncInit = () =&gt; {
                FB.init({
                    appId      : 'myappID',
                    cookie     : true, 
                    xfbml      : true, 
                    version    : 'v2.5'
                });

            }
        if (typeof(FB) == 'undefined') {
            ((d, s, id) =&gt; {
              let js, fjs = d.getElementsByTagName(s)[0];
              if (d.getElementById(id)) return;
              js = d.createElement(s);
              js.id = id;
              js.src = "//connect.facebook.net/en_US/sdk.js";
              fjs.parentNode.insertBefore(js, fjs);
            })(document, 'script', 'facebook-jssdk');
        }
    }
}

export default Facebook
</code></pre>

<p>And in my component I am checking if the user is logged in via facebook.. so in my <code>ComponentDidMount</code> I am doing something like ...</p>

<pre><code>let facebook = new Facebook()
console.log(FB)
FB.getLoginStatus(function(response){
    if(response.status == "connected"){
    //Do something
}
})
</code></pre>

<p>Here while <code>FB</code> is loaded async my <code>console.log(FB)</code> is called first. So it is giving me error <code>FB</code> is not defined.</p>

<p>But if I do <code>console.log(FB)</code> in <code>ComponentWillUnmount</code> it does not give error instead it gives desired output. </p>

<p>How can I load the <code>sdk</code> asynchronously and then only check of <code>FB.getLoginStatus</code>.</p>

<p>Need some help ...</p>