私は自分のプロジェクトでFacebookログイン機能を行っていますが、ログイン成功時には私はsetState
できません。このエラーはthis.setState is not a function
です。 setState
に成功した後、別の関数呼び出しを作成しようとしましたが、結果は同じで、私の関数は関数ではないことを伝えています。私は何をすべきか ?React Native - FacebookのログインはsetStateできません
constructor(props) {
super(props);
this.state = {
fblogindone:false,
};
}
_fbAuth(){
// Attempt a login using the Facebook login dialog asking for default permissions and email.
LoginManager.logInWithReadPermissions(['public_profile', 'email']).then(
function(result) {
if (result.isCancelled) {
alert('Login cancelled');
} else {
// Create response callback.
const responseInfoCallback = function(error, result) {
if (error) {
console.log(error);
alert('Error fetching data: ' + error.toString());
} else {
console.log(JSON.stringify(result));
this.setState({
fblogindone:true
});
}
}
// Create a graph request asking for user email and names with a callback to handle the response.
const infoRequest = new GraphRequest('/me',{
parameters: {
fields: {
string: 'id,name,email'
}
}
},
responseInfoCallback
);
// Start the graph request.
new GraphRequestManager().addRequest(infoRequest).start()
}
},
function(error) {
alert('Login fail with error: ' + error);
}
);
}
render() {
return(
<View style={styles.topcontainer}>
<TouchableOpacity activeOpacity={0.9} onPress={()=> this._fbAuth()}>
<FoIcon name="user-circle-o" size={33} color="#fff"/>
</TouchableOpacity>
</View>
);
}
使用の両方 '_fbAuth =()=> { 'と' this._fbAuth = this._fbAuth.bind(これは) 'も同じ結果を持って' this.setStateがあるfunction' –
私は答えられない私自分の質問 –