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/withUIRouter.tsx
2023-05-14 16:24:37 +07:00

22 lines
648 B
TypeScript

import { ComponentType } from 'react';
import { UIRouterContextComponent } from '@uirouter/react-hybrid';
export function withUIRouter<T>(
WrappedComponent: ComponentType<T>
): ComponentType<T> {
// Try to create a nice displayName for React Dev Tools.
const displayName =
WrappedComponent.displayName || WrappedComponent.name || 'Component';
function WrapperComponent(props: T & JSX.IntrinsicAttributes) {
return (
<UIRouterContextComponent>
<WrappedComponent {...props} />
</UIRouterContextComponent>
);
}
WrapperComponent.displayName = `withUIRouter(${displayName})`;
return WrapperComponent;
}