diff --git a/src/Async.tsx b/src/Async.tsx index 46838f7..8ae1dc7 100644 --- a/src/Async.tsx +++ b/src/Async.tsx @@ -118,3 +118,27 @@ export function Await({ async, children, fallback }: { // Promise is fulfilled, rendering the children with result data. return children(async.data); } + +/** + * Easy async component with fallback and fulfilled children render. + * @param promise The promise. + * @param children Renderer function of the children, takes promised data as argument. + * @param fallback Content shown when the promise is not fulfilled yet. + * @constructor + */ +export function Async({promise, fallback, children}: { + promise: Promisable|PromiseFn; + children: (async: T) => React.ReactElement; + fallback?: React.ReactElement; +}) +{ + // Get async data from given promise. + const async = useAsync(promise, [promise]); + + return ( + // Wait for promised data. + + {children} + + ) +}