Skip to content

Instantly share code, notes, and snippets.

@SangeetAgarwal
Last active September 7, 2020 19:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SangeetAgarwal/d82efebd136f51e0352fb9ca487c558c to your computer and use it in GitHub Desktop.
Save SangeetAgarwal/d82efebd136f51e0352fb9ca487c558c to your computer and use it in GitHub Desktop.
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