1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 05:19:39 +02:00
portainer/app/react-tools/withReactQuery.tsx
2023-05-14 16:24:37 +07:00

25 lines
803 B
TypeScript

import { ComponentType } from 'react';
import { QueryClientProvider } from 'react-query';
import { queryClient as defaultQueryClient } from './react-query';
export function withReactQuery<T>(
WrappedComponent: ComponentType<T & JSX.IntrinsicAttributes>,
queryClient = defaultQueryClient
): ComponentType<T & JSX.IntrinsicAttributes> {
// Try to create a nice displayName for React Dev Tools.
const displayName =
WrappedComponent.displayName || WrappedComponent.name || 'Component';
function WrapperComponent(props: T & JSX.IntrinsicAttributes) {
return (
<QueryClientProvider client={queryClient}>
<WrappedComponent {...props} />
</QueryClientProvider>
);
}
WrapperComponent.displayName = `withReactQuery(${displayName})`;
return WrapperComponent;
}