UNPKG

3.47 kBTypeScriptView Raw
1// NOTE: Users of the `experimental` builds of React should add a reference
2// to 'react-dom/experimental' in their project. See experimental.d.ts's top comment
3// for reference and documentation on how exactly to do it.
4
5export as namespace ReactDOM;
6
7import {
8 CElement,
9 Component,
10 ComponentState,
11 DOMAttributes,
12 DOMElement,
13 FunctionComponentElement,
14 ReactElement,
15 ReactInstance,
16 ReactNode,
17 ReactPortal,
18} from "react";
19
20export function findDOMNode(instance: ReactInstance | null | undefined): Element | null | Text;
21export function unmountComponentAtNode(container: Element | DocumentFragment): boolean;
22
23export function createPortal(
24 children: ReactNode,
25 container: Element | DocumentFragment,
26 key?: null | string,
27): ReactPortal;
28
29export const version: string;
30export const render: Renderer;
31export const hydrate: Renderer;
32
33export function flushSync<R>(fn: () => R): R;
34export function flushSync<A, R>(fn: (a: A) => R, a: A): R;
35
36export function unstable_batchedUpdates<A, R>(callback: (a: A) => R, a: A): R;
37export function unstable_batchedUpdates<R>(callback: () => R): R;
38
39export function unstable_renderSubtreeIntoContainer<T extends Element>(
40 parentComponent: Component<any>,
41 element: DOMElement<DOMAttributes<T>, T>,
42 container: Element,
43 callback?: (element: T) => any,
44): T;
45export function unstable_renderSubtreeIntoContainer<P, T extends Component<P, ComponentState>>(
46 parentComponent: Component<any>,
47 element: CElement<P, T>,
48 container: Element,
49 callback?: (component: T) => any,
50): T;
51export function unstable_renderSubtreeIntoContainer<P>(
52 parentComponent: Component<any>,
53 element: ReactElement<P>,
54 container: Element,
55 callback?: (component?: Component<P, ComponentState> | Element) => any,
56 // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
57): Component<P, ComponentState> | Element | void;
58
59export type Container = Element | Document | DocumentFragment;
60
61export interface Renderer {
62 // Deprecated(render): The return value is deprecated.
63 // In future releases the render function's return type will be void.
64
65 <T extends Element>(
66 element: DOMElement<DOMAttributes<T>, T>,
67 container: Container | null,
68 callback?: () => void,
69 ): T;
70
71 (
72 element: Array<DOMElement<DOMAttributes<any>, any>>,
73 container: Container | null,
74 callback?: () => void,
75 ): Element;
76
77 (
78 element: FunctionComponentElement<any> | Array<FunctionComponentElement<any>>,
79 container: Container | null,
80 callback?: () => void,
81 ): void;
82
83 <P, T extends Component<P, ComponentState>>(
84 element: CElement<P, T>,
85 container: Container | null,
86 callback?: () => void,
87 ): T;
88
89 (
90 element: Array<CElement<any, Component<any, ComponentState>>>,
91 container: Container | null,
92 callback?: () => void,
93 ): Component<any, ComponentState>;
94
95 <P>(
96 element: ReactElement<P>,
97 container: Container | null,
98 callback?: () => void,
99 // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
100 ): Component<P, ComponentState> | Element | void;
101
102 (
103 element: ReactElement[],
104 container: Container | null,
105 callback?: () => void,
106 // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
107 ): Component<any, ComponentState> | Element | void;
108}