, xhr
.
, XMLHttpRequest .
Redux Thunk, - :
function fetchPost(id) {
return dispatch => {
const xhr = makePostRequest(id);
dispatch({ type: 'FETCH_POST_REQUEST', response, id });
trackXHR(xhr,
(response) => dispatch({ type: 'FETCH_POST_SUCCESS', response, id }),
(err) => dispatch({ type: 'FETCH_POST_FAILURE', err, id })
);
return { abort: () => xhr.abort() };
};
}
abort
:
componentDidMount() {
this.requests = [];
this.requests.push(
this.props.dispatch(fetchPost(this.props.postId))
);
}
componentWillUnmount() {
this.requests.forEach(request => request.abort());
}