Skip to content
Advertisement

how can I use facebook SDK in react

I’m currently using react, and by using react-facebook-rogin Library, I successfully made facebook login. However, there is no function for logout!.

So I decided to use facebook SDK, however I don’t know how to use javascript code in react.

according to facebook official document, I need to write following code in HTML.

JavaScript

And after, this is the code for log out

JavaScript

And this is the code that I used react-facebook-rogin Library.

JavaScript

How can I use javascript code in react code?

Advertisement

Answer

I would not use a library that is 3 years old for this, but you could try using “window.FB.logout” or “FB.logout” on click. Either way, instead of that old dependency, you could just load the JS SDK on your own. Here is an example how that could work (untested):

JavaScript

This should be a component that is only loaded once – a root component that is always there, for example.

In that case, you can use FB.logout() as well, of course.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement