fix: flickering while loading

This commit is contained in:
Shashank Bairy R
2020-09-29 16:14:33 +05:30
parent 7c78bc66b2
commit 81703f1f1a
2 changed files with 7 additions and 4 deletions
+3 -2
View File
@@ -46,9 +46,10 @@ const DefaultEntityPage = () => (
);
const EntityPageSwitch = ({ EntityPage }: { EntityPage: ComponentType }) => {
const { entity } = useEntity();
const { entity, loading, error } = useEntity();
// Loading and error states
if (!entity) return <EntityNotFound />;
if (loading) return <EntityPageLayout />;
if (error || (!loading && !entity)) return <EntityNotFound />;
// Otherwise EntityPage provided from the App
// Note that EntityPage will include EntityPageLayout already
+4 -2
View File
@@ -58,6 +58,8 @@ export const useEntityFromUrl = (): EntityLoadingStatus => {
* Always going to return an entity, or throw an error if not a descendant of a EntityProvider.
*/
export const useEntity = () => {
const { entity } = useContext<{ entity: Entity }>(EntityContext as any);
return { entity };
const { entity, loading, error } = useContext<EntityLoadingStatus>(
EntityContext as any,
);
return { entity, loading, error };
};