useEffect(() => { const ourRequest = Axios.CancelToken.source() // <-- 1st step const fetchPost = async () => { try { const response = await Axios.get(`endpointURL`, { cancelToken: ourRequest.token, // <-- 2nd step }) console.log(response.data) setPost(response.data) setIsLoading(false) } catch (err) { console.log('There was a problem or request was cancelled.') } } fetchPost() return () => { ourRequest.cancel() // <-- 3rd step } }, [])
How to cancel/abort ajax request in axios
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment