Last active
September 7, 2020 19:30
-
-
Save SangeetAgarwal/d82efebd136f51e0352fb9ca487c558c to your computer and use it in GitHub Desktop.
This file contains 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
React.useEffect(() => { | |
setLoading(true); | |
const source = axios.CancelToken.source(); | |
async function fetchData() { | |
try { | |
// Get all the Category content areas & topics | |
const dataAccess = new DataAccess.Client(props.user); | |
const categories = await dataAccess.getCategoryContentAreas(source.token); | |
// ... set state | |
// Get the resource | |
const resource = await dataAccess.getResource(query.get("id") as string, source.token); | |
// ... set state | |
} catch (ex) { | |
if (axios.isCancel(ex)) { | |
console.log("request cancelled"); | |
} else { | |
const error = ex as AxiosError; | |
ExceptionService.StandardErrorHandler(error.response as AxiosResponse, enqueueSnackbar); | |
} | |
} finally { | |
setLoading(false); | |
} | |
} | |
fetchData(); | |
return function cleanup() { | |
source.cancel(); | |
}; | |
// eslint-disable-next-line react-hooks/exhaustive-deps | |
}, []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment