2
我有以下警告:警告:setState(...):只能更新已安裝或已安裝的組件。這通常意味着您在卸載的組件上調用了setState()。這是一個沒有操作。請檢查Home組件的代碼。如何更改componentDidMount上React Native的狀態?
export default class Home extends Component {
constructor(props) {
super(props);
this.state = {
loaded: false,
failed: false
};
}
componentWillMount() {
Actions.auth();
}
componentDidMount() {
Actions.loadUser.completed.listen(this.onLoadUserCompleted.bind(this));
Actions.goHome.listen(this.onGoHome.bind(this));
Actions.logout.listen(this.onLogout.bind(this));
}
onLoadUserCompleted(user) {
let currentUser = DataStore.getCurrentUser();
this.setState ({ loaded: true }); // <=============
}
}