React facebook登录根本不起作用 - 我缺少什么?

时间:2017-09-04 22:13:01

标签: reactjs facebook-login

我试图包括反应Facebook登录,并且正如在脸书文档(https://github.com/keppelen/react-facebook-login)中描述的那样,但不断出现奇怪的错误。我很快就做出反应并且一直在查看我的代码,但是我不知道我做错了什么,因为我正在做他们的文档中描述的确切内容。任何帮助都会非常感激!谢谢!

错误:const responseFacebook的意外标记:

            import React from 'react';
            import ReactDOM from 'react-dom';
            import  FacebookLogin  from 'react-facebook-login';

            class Login extends React.Component{             
              constructor (props, context) {
                super(props, context);
              }

             const responseFacebook = (response) => {
              console.log(response);
            }

              render () {
                return (
                  <div>
                   <FacebookLogin
                    appId="1112xxx"
                    autoLoad={true}
                    fields="name,email,picture"
                    onClick={componentClicked}
                    callback={this.responseFacebook} />
                  </div>
                );
              }

            }

            export default Login;

将responseFacebook功能更改为:

  constructor (props, context) {
        super(props, context);
         this.responseFacebook=responseFacebook.this.bind(this);
      }
    responseFacebook (response){
      console.log(response);
    }

给我这个错误:没有定义responseFacebook

更新(仍然没有正常工作的代码):

        import React from 'react';
        import ReactDOM from 'react-dom';
        import  FacebookLogin  from 'react-facebook-login';

        class Login extends React.Component{

                  constructor (props, context) {
                    super(props, context);
                     this.responseFacebook=responseFacebook.this.bind(this);
                  }


                responseFacebook = (response) => {
                     console.log(response);
                }

          render () {
            return (
              <div>
               <FacebookLogin
            appId="1112954322170315"
            autoLoad={true}
            fields="name,email,picture"
            onClick={componentClicked}
            callback={this.responseFacebook} />

              </div>
            );
          }

        }

        export default Login;

1 个答案:

答案 0 :(得分:0)

改变这一点;

const responseFacebook = (response) => {
    console.log(response);
}

对此;

responseFacebook = (response) => {
    console.log(response);
}

或者你这样做

responseFacebook(response) {
    console.log(response);
}

render () {
    return (
        <div>
            <FacebookLogin
                appId="1112xxx"
                autoLoad={true}
                fields="name,email,picture"
                onClick={componentClicked}
                callback={this.responseFacebook.bind(this)} 
            />
        </div>
        );
    }
}