I\'m trying to load the facebook comments plugin in a ReactJS app that\'s currently using React Router.
If I put the facebook init code inside my page\'s componentDidMou
You can place FB.XFBML.parse()
in componentDidUpdate()
but it works only when component updates as componentDidUpdate()
is a update life cycle method. This solution won't work if you navigate to some other component and then come back to it. Because in this case, componentDidMount()
called again but not componentDidUpdate. So, its better to place FB.XFBML.parse()
in top of componentDidMount()
.
componentDidMount() {
if(window.FB){
FB.XFBML.parse();
}
// all other code is same
}