So I have a route that needs to check if a user has access to the page by checking some data that's being asynchronously populated and is needed to check against the role of the user. Right now, I have a dispatch happening to fetch some data, but is there any way I can wait until that fetch is finished so and access the data?
Here is what my dispatch code looks like:
componentWillMount() {
this.props.dispatch(fetchWorkOrder(this.props.params.id));
}
And then here is my code for connecting and mapping state to props and all that:
const mapStateToProps = createStructuredSelector({
workOrder: selectWorkOrderPage(),
authentication: selectAuthentication(),
user: selectUser(),
});
function mapDispatchToProps(dispatch) {
return {
dispatch,
fetchWorkOrder,
};
}
export default connect(mapStateToProps, mapDispatchToProps)(WorkOrderPage);
Is there anything I can do to wait until this.props.dispatch(fetchWorkOrder(this.props.params.id));
is done loading so I can run some code, such as I would if it were a promise with a .then()
?
Thanks in advance!