React JS:无法读取未定义的属性“状态”

时间:2019-03-16 12:26:14

标签: javascript reactjs react-native

我想使用输入中的数据来更新数据。我收到以下错误。

未处理的拒绝(TypeError):无法读取未定义的属性“状态”

如何解决该问题?这是我的代码

state = {
  value: "",
  uid: ""
};

handleChange(event) {
  this.setState({ value: event.target.value });
}

handleSubmit = event => {
  event.preventDefault();

  fire.auth().onAuthStateChanged(user => {
    if (user) {
      this.setState({ uid: fire.auth().currentUser.uid });

      const db = fire.firestore();

      db.collection("Users")
        .where("uid", "==", this.state.uid)
        .get()

        .then(function(querySnapshot) {
          querySnapshot.forEach(function(doc) {
            console.log(doc.id, " => ", doc.data());
            // Build doc ref from doc.id
            db.collection("Users")
              .doc(doc.id)
              .update({ name: this.state.value });
          });
        });
    } else {
      // No user is signed in.
    }
  });
};

0 个答案:

没有答案