UNPKG

2.12 kBTypeScriptView Raw
1/**
2 * These are types for things that are present in the upcoming React 18 release.
3 *
4 * Once React 18 is released they can just be moved to the main index file.
5 *
6 * To load the types declared here in an actual project, there are three ways. The easiest one,
7 * if your `tsconfig.json` already has a `"types"` array in the `"compilerOptions"` section,
8 * is to add `"react-dom/next"` to the `"types"` array.
9 *
10 * Alternatively, a specific import syntax can to be used from a typescript file.
11 * This module does not exist in reality, which is why the {} is important:
12 *
13 * ```ts
14 * import {} from 'react-dom/next'
15 * ```
16 *
17 * It is also possible to include it through a triple-slash reference:
18 *
19 * ```ts
20 * /// <reference types="react-dom/next" />
21 * ```
22 *
23 * Either the import or the reference only needs to appear once, anywhere in the project.
24 */
25
26// See https://github.com/facebook/react/blob/master/packages/react-dom/src/client/ReactDOM.js to see how the exports are declared,
27
28import React = require('react');
29import ReactDOM = require('.');
30
31export {};
32
33declare module '.' {
34 interface HydrationOptions {
35 onHydrated?(suspenseInstance: Comment): void;
36 onDeleted?(suspenseInstance: Comment): void;
37 }
38
39 interface RootOptions {
40 /**
41 * @deprecated Use `hydrateRoot(container)` instead
42 */
43 hydrate?: boolean | undefined;
44 /**
45 * @deprecated Use `hydrateRoot(container, hydrateOptions)` instead
46 */
47 hydrationOptions?: HydrationOptions | undefined;
48 }
49
50 interface Root {
51 render(children: React.ReactChild | React.ReactNodeArray): void;
52 unmount(): void;
53 }
54
55 /**
56 * Replaces `ReactDOM.render` when the `.render` method is called and enables Concurrent Mode.
57 *
58 * @see https://reactjs.org/docs/concurrent-mode-reference.html#createroot
59 */
60 function createRoot(container: Element | Document | DocumentFragment | Comment, options?: RootOptions): Root;
61
62 function hydrateRoot(container: Element | Document | DocumentFragment | Comment, options?: HydrationOptions): Root;
63}