在React Native中使用componentDidMount()
作为异步函数是一种很好的做法,还是应该避免使用?
当组件挂载时,我需要从AsyncStorage
获得一些信息,但我所知道的唯一方法是使componentDidMount()
功能异步。
async componentDidMount() {
let auth = await this.getAuth();
if (auth)
this.checkAuth(auth);
}
这有什么问题吗?这个问题还有其他解决办法吗?