vega-frontend-monorepo/apps/trading/components/async-renderer/async-renderer.tsx
Matthew Russell d4652b3dd8
Task/Strict mode enabled for trading app (#150)
* enable strict mode and fix resulting type errors

* fix print affected command

* remove assign-deep and use lodash/merge, fix some type errors after enabling strict mode
2022-03-28 12:34:45 -07:00

28 lines
567 B
TypeScript

import { Splash } from '@vegaprotocol/ui-toolkit';
import { ReactNode } from 'react';
interface AsyncRendererProps<T> {
loading: boolean;
error: Error | undefined | null;
data: T | undefined;
children: (data: T) => ReactNode;
}
// eslint-disable-next-line
export function AsyncRenderer<T = any>({
loading,
error,
data,
children,
}: AsyncRendererProps<T>) {
if (error) {
return <Splash>Something went wrong: {error.message}</Splash>;
}
if (loading || !data) {
return <Splash>Loading...</Splash>;
}
return <>{children(data)}</>;
}