d4652b3dd8
* 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
25 lines
764 B
TypeScript
25 lines
764 B
TypeScript
import { OperationVariables, QueryHookOptions, useQuery } from '@apollo/client';
|
|
import { DocumentNode } from 'graphql';
|
|
import { ReactNode } from 'react';
|
|
import { AsyncRenderer } from '../async-renderer';
|
|
|
|
interface PageQueryContainerProps<TData, TVariables> {
|
|
query: DocumentNode;
|
|
options?: QueryHookOptions<TData, TVariables>;
|
|
children: (data: TData) => ReactNode;
|
|
}
|
|
|
|
export const PageQueryContainer = <TData, TVariables = OperationVariables>({
|
|
query,
|
|
options,
|
|
children,
|
|
}: PageQueryContainerProps<TData, TVariables>) => {
|
|
const { data, loading, error } = useQuery<TData, TVariables>(query, options);
|
|
|
|
return (
|
|
<AsyncRenderer<TData> loading={loading} error={error} data={data}>
|
|
{(data) => children(data)}
|
|
</AsyncRenderer>
|
|
);
|
|
};
|