0
別のメソッドからメソッドを呼び出そうとしていますが、 "writeUserData"というエラーは定義されていません。 これは私のコードです:私のメソッドが定義されていません
export default class RegisterScreen extends Component{
constructor(props){
super(props)
this.state = {
email: '',
password: '',
verify: '',
nickname: '',
}
this.handlePress = this.handlePress.bind(this)
this.writeUserData = this.writeUserData.bind(this)
}
handlePress(navigation){
if(this.state.password == this.state.verify){
firebaseRef.auth().createUserWithEmailAndPassword(this.state.email, this.state.password).then(function(newUser){
const resetAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'Home'})
]
})
navigation.dispatch(resetAction)
writeUserData(newUser.uid, this.nickname); //Problem here.
}).catch(function(error){
console.log(error);
});
}else{
//password not match, show error.
}
}
writeUserData(mUID, mNickname){
console.log("WRITE");
firebaseRef.database().ref('users/' + mUID + '/').set({
nickname: mNickname,
});
}
}
私は、データベースへの登録後、ユーザーのニックネームとUIDの書き込みしようとしています。 私はFirebaseとReact Nativeを使用しています。
私もthis.writeUserDataを書き込もうとしましたが、「this.writeUserData」は関数ではないというエラーが表示されます。
私は間違っていますが、どうすれば修正できますか?
ありがとうございます!
をありがとう!この矢印機能の詳細はどこで知ることができますか? –
矢印機能はes6です。詳しくはこちらをご覧ください:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions –
ありがとう、ありがとうございました。 –