This commit is contained in:
Zeeshaun
2026-03-23 11:21:52 -05:00
parent de9ddd5001
commit a17bc4b4a9
426 changed files with 60574 additions and 1 deletions
@@ -0,0 +1,35 @@
import React from "react";
import AsyncState from "../../shared/enumerations/AsyncState";
import IAsyncStateContainer from "../../shared/types/IAsyncStateContainer";
export interface IAsyncProps {
container: IAsyncStateContainer<any>;
children: JSX.Element;
error?: JSX.Element;
loading?: JSX.Element;
notFound?: JSX.Element;
inactive?: JSX.Element;
}
const AsyncGuard: React.FC<IAsyncProps> = (props) => {
switch (props.container.state) {
case AsyncState.Inactive:
default:
return props.inactive ? props.inactive : <></>;
case AsyncState.Loading:
return props.loading ? props.loading : <>Loading...</>;
case AsyncState.Invalid:
case AsyncState.Failure:
return props.error ? props.error : <>Data failed to load</>;
case AsyncState.NotFound:
return props.notFound ? props.notFound : <>Data was not found</>;
case AsyncState.Success:
return props.container.data ? (
props.children
) : (
<>No Data Returned</>
);
}
};
export default AsyncGuard;