私はcomponentWillMountで呼び出しているアクション作成者を持っています。そのアクションペイロードの戻り値はsetStateを使用して状態に割り当てられています。しかし、componentDidMountでは、非同期呼び出しがまだ完了していないため、そのプロパティにアクセスできません。 compoentDidMountでこのデータにアクセスする正しい方法は何ですか?ReactuxアクションペイロードがcomponentDidMountにありません
//component
class Dashboard extends Component {
componentWillMount() {
this.setState(this.props.getUser());
}
componentDidMount() {
// this.state.user isn't available yet
}
render(){
return(...);
}
}
//action
export function getUser() {
return async function (dispatch) {
const user = await axios.get(`${API_URL}user?token=${token}`);
return dispatch({
type: USER,
payload: user,
});
}
};
}