2022-09-20 18:14:24 +00:00
|
|
|
import { ComponentType } from 'react';
|
|
|
|
import { QueryClientProvider } from 'react-query';
|
|
|
|
|
|
|
|
import { queryClient as defaultQueryClient } from './react-query';
|
|
|
|
|
|
|
|
export function withReactQuery<T>(
|
2023-05-14 09:24:37 +00:00
|
|
|
WrappedComponent: ComponentType<T & JSX.IntrinsicAttributes>,
|
2022-09-20 18:14:24 +00:00
|
|
|
queryClient = defaultQueryClient
|
2023-05-14 09:24:37 +00:00
|
|
|
): ComponentType<T & JSX.IntrinsicAttributes> {
|
2022-09-20 18:14:24 +00:00
|
|
|
// Try to create a nice displayName for React Dev Tools.
|
|
|
|
const displayName =
|
|
|
|
WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
|
|
|
2023-05-14 09:24:37 +00:00
|
|
|
function WrapperComponent(props: T & JSX.IntrinsicAttributes) {
|
2022-09-20 18:14:24 +00:00
|
|
|
return (
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<WrappedComponent {...props} />
|
|
|
|
</QueryClientProvider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-26 02:10:05 +00:00
|
|
|
WrapperComponent.displayName = `withReactQuery(${displayName})`;
|
2022-09-20 18:14:24 +00:00
|
|
|
|
|
|
|
return WrapperComponent;
|
|
|
|
}
|