UNPKG

4.36 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 { Key, ReactNode, ReactPortal } from "react";
8
9export function createPortal(
10 children: ReactNode,
11 container: Element | DocumentFragment,
12 key?: Key | null,
13): ReactPortal;
14
15export const version: string;
16
17export function flushSync<R>(fn: () => R): R;
18
19export function unstable_batchedUpdates<A, R>(callback: (a: A) => R, a: A): R;
20export function unstable_batchedUpdates<R>(callback: () => R): R;
21
22export interface FormStatusNotPending {
23 pending: false;
24 data: null;
25 method: null;
26 action: null;
27}
28
29export interface FormStatusPending {
30 pending: true;
31 data: FormData;
32 method: string;
33 action: string | ((formData: FormData) => void | Promise<void>);
34}
35
36export type FormStatus = FormStatusPending | FormStatusNotPending;
37
38export function useFormStatus(): FormStatus;
39
40export function useFormState<State>(
41 action: (state: Awaited<State>) => State | Promise<State>,
42 initialState: Awaited<State>,
43 permalink?: string,
44): [state: Awaited<State>, dispatch: () => void, isPending: boolean];
45export function useFormState<State, Payload>(
46 action: (state: Awaited<State>, payload: Payload) => State | Promise<State>,
47 initialState: Awaited<State>,
48 permalink?: string,
49): [state: Awaited<State>, dispatch: (payload: Payload) => void, isPending: boolean];
50
51export function prefetchDNS(href: string): void;
52
53export interface PreconnectOptions {
54 // Don't create a helper type.
55 // It would have to be in module scope to be inlined in TS tooltips.
56 // But then it becomes part of the public API.
57 // TODO: Upstream to microsoft/TypeScript-DOM-lib-generator -> w3c/webref
58 // since the spec has a notion of a dedicated type: https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attribute
59 crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
60}
61export function preconnect(href: string, options?: PreconnectOptions): void;
62
63export type PreloadAs =
64 | "audio"
65 | "document"
66 | "embed"
67 | "fetch"
68 | "font"
69 | "image"
70 | "object"
71 | "track"
72 | "script"
73 | "style"
74 | "video"
75 | "worker";
76export interface PreloadOptions {
77 as: PreloadAs;
78 crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
79 fetchPriority?: "high" | "low" | "auto" | undefined;
80 // TODO: These should only be allowed with `as: 'image'` but it's not trivial to write tests against the full TS support matrix.
81 imageSizes?: string | undefined;
82 imageSrcSet?: string | undefined;
83 integrity?: string | undefined;
84 type?: string | undefined;
85 nonce?: string | undefined;
86 referrerPolicy?: ReferrerPolicy | undefined;
87}
88export function preload(href: string, options?: PreloadOptions): void;
89
90// https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload
91export type PreloadModuleAs = RequestDestination;
92export interface PreloadModuleOptions {
93 /**
94 * @default "script"
95 */
96 as: PreloadModuleAs;
97 crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
98 integrity?: string | undefined;
99 nonce?: string | undefined;
100}
101export function preloadModule(href: string, options?: PreloadModuleOptions): void;
102
103export type PreinitAs = "script" | "style";
104export interface PreinitOptions {
105 as: PreinitAs;
106 crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
107 fetchPriority?: "high" | "low" | "auto" | undefined;
108 precedence?: string | undefined;
109 integrity?: string | undefined;
110 nonce?: string | undefined;
111}
112export function preinit(href: string, options?: PreinitOptions): void;
113
114// Will be expanded to include all of https://github.com/tc39/proposal-import-attributes
115export type PreinitModuleAs = "script";
116export interface PreinitModuleOptions {
117 /**
118 * @default "script"
119 */
120 as?: PreinitModuleAs;
121 crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
122 integrity?: string | undefined;
123 nonce?: string | undefined;
124}
125export function preinitModule(href: string, options?: PreinitModuleOptions): void;
126
127export function requestFormReset(form: HTMLFormElement): void;