withTeams.tsx 776 B

123456789101112131415161718192021222324252627282930
  1. import * as React from 'react';
  2. import {Team} from 'sentry/types';
  3. import getDisplayName from 'sentry/utils/getDisplayName';
  4. import useTeams from 'sentry/utils/useTeams';
  5. type InjectedTeamsProps = {
  6. teams?: Team[];
  7. };
  8. /**
  9. * Higher order component that provides a list of teams
  10. *
  11. * @deprecated Prefer `useTeams` or `<Teams />`.
  12. */
  13. const withTeams = <P extends InjectedTeamsProps>(
  14. WrappedComponent: React.ComponentType<P>
  15. ) => {
  16. const WithTeams: React.FC<Omit<P, keyof InjectedTeamsProps> & InjectedTeamsProps> =
  17. props => {
  18. const {teams} = useTeams();
  19. return <WrappedComponent teams={teams} {...(props as P)} />;
  20. };
  21. WithTeams.displayName = `withTeams(${getDisplayName(WrappedComponent)})`;
  22. return WithTeams;
  23. };
  24. export default withTeams;