Closures
Function along with its lexical scope bundled together forms a closure. it's called Closures.
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 } }, [])