我是React的新手,我尝试创建一个函数:
我总结我的代码:
class Signup extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
}
writeUserData = (userId, username, email) => {
firebase.database().ref('users/' + userId).set({
username: username,
email: email
});
}
handleSubmit = (e) => {
if(!error) {
writeUserData(userID, username, email); //'writeUserData' is not defined no-undef
}
为什么我的writeUserData没有定义为un-undef?
答案 0 :(得分:5)
writeUserData
存在于类实例上,您需要像this.writeUserData(userID, username, email)
handleSubmit = (e) => {
if(!error) {
this.writeUserData(userID, username, email);
}