'FB' is not defined React facebook api login

100 Views Asked by At

I'm trying to add the javascript facebook login api to a create react app. I have defined the api details in a useEffect function but its still returning that FB isn't defined. How can I resolve this issue? Here is my code:

  useEffect(() => {

    (function(d, s, id){
       var js, fjs = d.getElementsByTagName(s)[0];
       if (d.getElementById(id)) {return;}
       js = d.createElement(s); js.id = id;
       js.src = "https://connect.facebook.net/en_US/sdk.js";
       fjs.parentNode.insertBefore(js, fjs);
     }(document, 'script', 'facebook-jssdk'));

      window.fbAsyncInit = function() {
        FB.init({
          appId      : 'id',
          cookie     : true,
          xfbml      : true,
          version    : 'v10.0'
        });
          
        FB.AppEvents.logPageView();  
      }
    }, []) 
0

There are 0 best solutions below