Implementing Facebook comments plugin in ReactJS app

后端 未结 2 463
自闭症患者
自闭症患者 2021-02-07 20:43

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

2条回答
  •  礼貌的吻别
    2021-02-07 21:38

    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
    }
    

提交回复
热议问题