mirror of
https://github.com/graphql-hive/console
synced 2026-04-21 14:37:17 +00:00
29 lines
805 B
TypeScript
29 lines
805 B
TypeScript
import { Component, ReactNode } from 'react';
|
|
import { AnyVariables, UseQueryState } from 'urql';
|
|
import { QueryError } from '@/components/ui/query-error';
|
|
|
|
export class DataWrapper<TData, TVariables extends AnyVariables> extends Component<{
|
|
query: UseQueryState<TData, TVariables>;
|
|
showStale?: boolean;
|
|
organizationId: string | null;
|
|
children(props: { data: TData }): ReactNode;
|
|
spinnerComponent?: ReactNode;
|
|
}> {
|
|
render() {
|
|
const { query, children, spinnerComponent } = this.props;
|
|
const { fetching, error, data } = query;
|
|
if (fetching) {
|
|
return spinnerComponent;
|
|
}
|
|
|
|
if (error) {
|
|
return <QueryError organizationId={this.props.organizationId} error={error} />;
|
|
}
|
|
|
|
if (!data) {
|
|
return spinnerComponent;
|
|
}
|
|
|
|
return children({ data });
|
|
}
|
|
}
|