Last active
October 8, 2020 10:40
-
-
Save ilhamgusti/42f2542e18580ed18a71313e6359fafd to your computer and use it in GitHub Desktop.
cancel fetching axios redux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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