首页 文章

onClick()没有调用facebook按钮 - reactJS

提问于
浏览
0

由于某种原因,我的onClick处理程序无法使用facebook按钮(在https://developers.facebook.com/docs/facebook-login/web/login-button/找到) . 但它将与一个共同的div一起工作 .

Any idea why the onClick isn't called on the facebook button (second div)?

<div onClick={this._handleFBLogin}>Facebook Login (working)</div>
<div onClick={this._handleFBLogin} 
   className="fb-login-button" 
   data-max-rows="1" 
   data-size="large" 
   data-button-type="continue_with" 
   data-show-faces="false" 
   data-auto-logout-link="false" 
   data-use-continue-as="false" />

Symptoms

onClick() 从来没有被叫过 .

EDIT: Follow Up

根据@ luschn的回复和其他一些问题(特别是:Implement Facebook API login with reactjs

我不得不绕过我的 _handleFBLogin() 函数,它调用了一个函数来处理facebook auth并直接处理facebook auth . 以下是 componentDidMount() 中的相关代码:

const facebookCallback = (response) => {
            return this._facebookCallback(response)
        }
        window.fbAsyncInit = function() {
            FB.init({
                appId      : FACEBOOK_APP_ID,
                cookie     : true,  // enable cookies to allow the server to access the session
                version    : FACEBOOK_API_VERSION
            });

            FB.Event.subscribe('auth.statusChange', function(response) {
                facebookCallback(response)
            });
        }.bind(this);

请注意绑定并订阅auth.statusChange .

此外,由于此订阅事件,我不需要添加 data-onlogin .

最后,我的原始_handleFBLogin代码是:

_handleFBLogin = () => {
        FB.login(response => {
            this._facebookCallback(response)
        }, {scope: 'public_profile,email'})
    }

1 回答

相关问题