Skip to content

Instantly share code, notes, and snippets.

@SangeetAgarwal
Created September 5, 2020 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SangeetAgarwal/62b957d7ff68c41c8337aca186878eac to your computer and use it in GitHub Desktop.
Save SangeetAgarwal/62b957d7ff68c41c8337aca186878eac to your computer and use it in GitHub Desktop.
use swr to fetch data & pass to presentation layer
const ResourceEditWrapper = () => {
const query = useQuery();
const classes = useStyles({});
// Resource
const {
resource,
isLoading: isResourceLoading,
error: resourceError,
} = useResource(query.get("id") as string);
// Categories
const {
categories: mappedCategories,
isLoading: isCategoriesLoading,
error: categoriesError,
} = useCategories();
// CategoryContentAreas
const {
categoryContentAreas: mappedCategoryContentAreas,
isLoading: isCategoryContentAreasLoading,
error: categoryContentAreasError,
} = useCategoryContentAreas();
// Topics
const {
topics: mappedTopics,
isLoading: isTopicsLoading,
error: topicsError,
} = useTopics();
if (topicsError) {
return <h1>Something went wrong</h1>;
}
if (categoryContentAreasError) {
return <h1>Something went wrong</h1>;
}
if (categoriesError) {
return <h1>Something went wrong</h1>;
}
if (resourceError) {
return <h1>Something went wrong</h1>;
}
if (
resource != null &&
mappedCategories != null &&
mappedCategoryContentAreas != null &&
mappedTopics != null
)
return (
<ResourceEdit
resource={resource}
mappedCategories={mappedCategories}
mappedCategoryContentAreas={mappedCategoryContentAreas}
mappedTopics={mappedTopics}
/>
);
if (
isResourceLoading ||
isCategoryContentAreasLoading ||
isCategoriesLoading ||
isTopicsLoading
)
return (
<div className={classes.loader}>
<LinearProgress />
<LinearProgress color="secondary" />
<span>
{" "}
<Typography variant="h5">Getting information ...</Typography>
</span>
</div>
);
};
export default ResourceEditWrapper;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment