import {Client} from 'sentry/api';
import getDisplayName from 'sentry/utils/getDisplayName';
import useApi from 'sentry/utils/useApi';
type InjectedApiProps = {
api: Client;
};
type WrappedProps
= Omit
& Partial;
/**
* XXX: Prefer useApi if you are wrapping a Function Component!
*
* React Higher-Order Component (HoC) that provides "api" client when mounted,
* and clears API requests when component is unmounted.
*
* If an `api` prop is provided when the component is invoked it will be passed
* through.
*/
const withApi = (
WrappedComponent: React.ComponentType
,
options: Parameters[0] = {}
) => {
const WithApi: React.FC> = ({api: propsApi, ...props}) => {
const api = useApi({api: propsApi, ...options});
return ;
};
WithApi.displayName = `withApi(${getDisplayName(WrappedComponent)})`;
return WithApi;
};
export default withApi;