I have a method lookupComplete
in react component that call action checkIfAssign
, I need wait to response and depend on this response trigger in this method another methods. But recieve Promise {<pending>} "result"
. How to wait until resolve this action ?
Component:
export class Test extends Component {
....
lookupComplete = (tagId = this.state.tagId) =>
this.setState({tagId}, () => {
let result = this.props
.checkIfAssign(this.state.tagId, this.props.accessToken)
result.status
? this.triggerTransition(transitions.ClickCheckTag)
: this.triggerTransition(transitions.Test)
})
}
export const mapDispatchToProps = dispatch => ({
checkIfAssign: (tagId, accessToken) =>
dispatch(TagAssignmentActions.checkTagAssignment(tagId, accessToken)),
})
Action:
export const checkTagAssignment = (tagId, token) => async dispatch => {
dispatch({
type: TagAssignmentActionTypes.TagAssignmentChanged,
})
let status, assignee, response
try {
response = await DeviceApi.checkTagAssignment(tagId, token)
assignee = response.result.assignee
status = response.result.status
} catch (e) {
if (e && e.status === httpStatusCode.notFound)
status = TagStatus.NotFound
}
dispatch({
type: TagAssignmentActionTypes.TagAssignmentChanged,
status,
assignee,
response,
})
console.log(response, 'response')
return response
}