withTeams.tsx 715 B

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