You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react-tools/withCurrentUser.tsx

28 lines
866 B

import { ComponentType } from 'react';
import { UserProvider } from '@/react/hooks/useUser';
import { withReactQuery } from './withReactQuery';
export function withCurrentUser<T>(
WrappedComponent: ComponentType<T & JSX.IntrinsicAttributes>
): 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 (
<UserProvider>
<WrappedComponent {...props} />
</UserProvider>
);
}
WrapperComponent.displayName = `withCurrentUser(${displayName})`;
// User provider makes a call to the API to get the current user.
// We need to wrap it with React Query to make that call.
return withReactQuery(WrapperComponent);
}