import React, { ComponentType } from 'react'; import { useRouter, useThrottlingLocation } from '../..'; import { RouterProps } from './withRouter'; import { getDisplayName } from '../tools'; export interface ThrottlingRouterProps extends RouterProps { onTransitionEnd: () => void; } /** * Смотри описание {@link useThrottlingLocation} * @param Component */ export function withThrottlingRouter(Component: ComponentType): ComponentType> { function WithThrottlingRouter(props: Omit) { const router = useRouter(false); const [location, onTransitionEnd] = useThrottlingLocation(); const routerProps: ThrottlingRouterProps = { router: router, onTransitionEnd: onTransitionEnd, routeState: location.state, location: location, route: location.route, }; // eslint-disable-next-line @typescript-eslint/consistent-type-assertions const allProps: T = { ...props, ...routerProps, } as T; return ; } WithThrottlingRouter.displayName = `WithThrottlingRouter(${getDisplayName(Component)})`; return WithThrottlingRouter; }