ComponentDidMount 我想添加 fetch API 和 FirebaseAuth

ComponentDidMount I want to add fetch API and FirebaseAuth

我想连接 firebase 的东西。我在新闻提要中尝试的是当我按 addTofavourite 时,它的名称应该转到 firebase。所以在我的获取代码中,我使用了 componentDidMount 并且对于发送也有 componentDidMount。我不知道如何连接它们。

这是我试过的方法,但没有用。

componentDidMount() {
   firebase.auth().signInWithEmailAndPassword
   ("web@imandy.ie", "123456")
//////////////////////////////////////
   this.fetchNews();
  }

用于获取新闻

 componentDidMount() {
    this.fetchNews();
  }

对于 firebase 的事情

componentDidMount() {

        firebase.auth().signInWithEmailAndPassword("web@imandy.ie", "123456" )
    }

您必须在 componentWillReciveProps(){} 或 componentDidUpdate() 中调用此函数{}

请这样尝试

componentDidMount = async () => {
   const { user }  = await firebase.auth().signInWithEmailAndPassword("web@imandy.ie", "123456");
   // If you want to use user detail, write code here
   // ...
   this.fetchNews();
}