Adding
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user