未在反应中定义'writeUserData'no-undef

时间:2020-05-04 13:43:00

标签: javascript reactjs

我是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?

1 个答案:

答案 0 :(得分:5)

writeUserData存在于类实例上,您需要像this.writeUserData(userID, username, email)

那样调用它
handleSubmit = (e) => {
    if(!error) {
            this.writeUserData(userID, username, email); 

    }