react-teleporter
Version:
Teleport React components in the same React tree.
30 lines (27 loc) • 1.01 kB
TypeScript
import * as React from 'react';
declare type As<Props = any> = React.ElementType<Props>;
declare type PropsWithAs<Props = {}, Type extends As = As> = Props & Omit<React.ComponentProps<Type>, "as" | keyof Props> & {
as?: Type;
};
declare type ComponentWithAs<Props, DefaultType extends As> = {
<Type extends As>(props: PropsWithAs<Props, Type> & {
as: Type;
}): JSX.Element;
(props: PropsWithAs<Props, DefaultType>): JSX.Element;
};
declare type ChildrenFunction = (target: Element) => React.ReactNode;
interface CreateTeleporterOptions {
multiSources?: Boolean;
}
interface TargetRef {
(element: Element | null): void;
}
interface Teleporter {
Source: React.FC<{
children: React.ReactNode | ChildrenFunction;
}>;
Target: ComponentWithAs<{}, "div">;
useTargetRef: () => TargetRef;
}
declare const createTeleporter: ({ multiSources, }?: CreateTeleporterOptions) => Teleporter;
export { CreateTeleporterOptions, TargetRef, Teleporter, createTeleporter };