Skip to content

Instantly share code, notes, and snippets.

@ilhamgusti
Last active October 8, 2020 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilhamgusti/42f2542e18580ed18a71313e6359fafd to your computer and use it in GitHub Desktop.
Save ilhamgusti/42f2542e18580ed18a71313e6359fafd to your computer and use it in GitHub Desktop.
cancel fetching axios redux
useEffect(() => {
const cancelToken = customAxios.CancelToken.source();
dispatch(fetchDataABC(match.params.id, cancelToken.token));
return () => {
cancelToken.cancel(`Cancel fetchData ${match.params.id}`)
}
}, []);
export const fetchDataABC = (id, cancelToken) => async dispatch => {
try {
const {data: info} = await axios.get(`/datalink/${id}`, {
cancelToken
});
dispatch({
type: FETCH_DATA_ABC,
payload: info
})
} catch (e) {
console.log("fetchData get error ", e);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment