1 | /**
|
2 | * These are types for things that are present in the `experimental` builds of React but not yet
|
3 | * on a stable build.
|
4 | *
|
5 | * Once they are promoted to stable they can just be moved to the main index file.
|
6 | *
|
7 | * To load the types declared here in an actual project, there are three ways. The easiest one,
|
8 | * if your `tsconfig.json` already has a `"types"` array in the `"compilerOptions"` section,
|
9 | * is to add `"react/experimental"` to the `"types"` array.
|
10 | *
|
11 | * Alternatively, a specific import syntax can to be used from a typescript file.
|
12 | * This module does not exist in reality, which is why the {} is important:
|
13 | *
|
14 | * ```ts
|
15 | * import {} from 'react/experimental'
|
16 | * ```
|
17 | *
|
18 | * It is also possible to include it through a triple-slash reference:
|
19 | *
|
20 | * ```ts
|
21 | * /// <reference types="react/experimental" />
|
22 | * ```
|
23 | *
|
24 | * Either the import or the reference only needs to appear once, anywhere in the project.
|
25 | */
|
26 |
|
27 | // See https://github.com/facebook/react/blob/master/packages/react/src/React.js to see how the exports are declared,
|
28 | // and https://github.com/facebook/react/blob/master/packages/shared/ReactFeatureFlags.js to verify which APIs are
|
29 | // flagged experimental or not. Experimental APIs will be tagged with `__EXPERIMENTAL__`.
|
30 | //
|
31 | // For the inputs of types exported as simply a fiber tag, the `beginWork` function of ReactFiberBeginWork.js
|
32 | // is a good place to start looking for details; it generally calls prop validation functions or delegates
|
33 | // all tasks done as part of the render phase (the concurrent part of the React update cycle).
|
34 | //
|
35 | // Suspense-related handling can be found in ReactFiberThrow.js.
|
36 |
|
37 | import React = require("./canary");
|
38 |
|
39 | export {};
|
40 |
|
41 | declare const UNDEFINED_VOID_ONLY: unique symbol;
|
42 | type VoidOrUndefinedOnly = void | { [UNDEFINED_VOID_ONLY]: never };
|
43 |
|
44 | declare module "." {
|
45 | export interface SuspenseProps {
|
46 | /**
|
47 | * The presence of this prop indicates that the content is computationally expensive to render.
|
48 | * In other words, the tree is CPU bound and not I/O bound (e.g. due to fetching data).
|
49 | * @see {@link https://github.com/facebook/react/pull/19936}
|
50 | */
|
51 | unstable_expectedLoadTime?: number | undefined;
|
52 | }
|
53 |
|
54 | export type SuspenseListRevealOrder = "forwards" | "backwards" | "together";
|
55 | export type SuspenseListTailMode = "collapsed" | "hidden";
|
56 |
|
57 | export interface SuspenseListCommonProps {
|
58 | /**
|
59 | * Note that SuspenseList require more than one child;
|
60 | * it is a runtime warning to provide only a single child.
|
61 | *
|
62 | * It does, however, allow those children to be wrapped inside a single
|
63 | * level of `<React.Fragment>`.
|
64 | */
|
65 | children: ReactElement | Iterable<ReactElement>;
|
66 | }
|
67 |
|
68 | interface DirectionalSuspenseListProps extends SuspenseListCommonProps {
|
69 | /**
|
70 | * Defines the order in which the `SuspenseList` children should be revealed.
|
71 | */
|
72 | revealOrder: "forwards" | "backwards";
|
73 | /**
|
74 | * Dictates how unloaded items in a SuspenseList is shown.
|
75 | *
|
76 | * - By default, `SuspenseList` will show all fallbacks in the list.
|
77 | * - `collapsed` shows only the next fallback in the list.
|
78 | * - `hidden` doesn’t show any unloaded items.
|
79 | */
|
80 | tail?: SuspenseListTailMode | undefined;
|
81 | }
|
82 |
|
83 | interface NonDirectionalSuspenseListProps extends SuspenseListCommonProps {
|
84 | /**
|
85 | * Defines the order in which the `SuspenseList` children should be revealed.
|
86 | */
|
87 | revealOrder?: Exclude<SuspenseListRevealOrder, DirectionalSuspenseListProps["revealOrder"]> | undefined;
|
88 | /**
|
89 | * The tail property is invalid when not using the `forwards` or `backwards` reveal orders.
|
90 | */
|
91 | tail?: never | undefined;
|
92 | }
|
93 |
|
94 | export type SuspenseListProps = DirectionalSuspenseListProps | NonDirectionalSuspenseListProps;
|
95 |
|
96 | /**
|
97 | * `SuspenseList` helps coordinate many components that can suspend by orchestrating the order
|
98 | * in which these components are revealed to the user.
|
99 | *
|
100 | * When multiple components need to fetch data, this data may arrive in an unpredictable order.
|
101 | * However, if you wrap these items in a `SuspenseList`, React will not show an item in the list
|
102 | * until previous items have been displayed (this behavior is adjustable).
|
103 | *
|
104 | * @see https://reactjs.org/docs/concurrent-mode-reference.html#suspenselist
|
105 | * @see https://reactjs.org/docs/concurrent-mode-patterns.html#suspenselist
|
106 | */
|
107 | export const unstable_SuspenseList: ExoticComponent<SuspenseListProps>;
|
108 |
|
109 | // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
110 | export function experimental_useEffectEvent<T extends Function>(event: T): T;
|
111 |
|
112 | type Reference = object;
|
113 | type TaintableUniqueValue = string | bigint | ArrayBufferView;
|
114 | function experimental_taintUniqueValue(
|
115 | message: string | undefined,
|
116 | lifetime: Reference,
|
117 | value: TaintableUniqueValue,
|
118 | ): void;
|
119 | function experimental_taintObjectReference(message: string | undefined, object: Reference): void;
|
120 |
|
121 | export interface ViewTransitionInstance {
|
122 | /**
|
123 | * The {@link ViewTransitionProps name} that was used in the corresponding {@link ViewTransition} component or `"auto"` if the `name` prop was omitted.
|
124 | */
|
125 | name: string;
|
126 | }
|
127 |
|
128 | export interface ViewTransitionProps {
|
129 | children?: ReactNode | undefined;
|
130 | /**
|
131 | * Assigns the {@link https://developer.chrome.com/blog/view-transitions-update-io24#view-transition-class `view-transition-class`} class to the underlying DOM node.
|
132 | */
|
133 | className?: string | undefined;
|
134 | /**
|
135 | * Combined with {@link className} if this `<ViewTransition>` or its parent Component is mounted and there's no other with the same name being deleted.
|
136 | * `"none"` is a special value that deactivates the view transition name under that condition.
|
137 | */
|
138 | enter?: "none" | (string & {}) | undefined;
|
139 | /**
|
140 | * Combined with {@link className} if this `<ViewTransition>` or its parent Component is unmounted and there's no other with the same name being deleted.
|
141 | * `"none"` is a special value that deactivates the view transition name under that condition.
|
142 | */
|
143 | exit?: "none" | (string & {}) | undefined;
|
144 | /**
|
145 | * Combined with {@link className} there are no updates to the content inside this boundary itself but the boundary has resized or moved due to other changes to siblings.
|
146 | * `"none"` is a special value that deactivates the view transition name under that condition.
|
147 | */
|
148 | layout?: "none" | (string & {}) | undefined;
|
149 | /**
|
150 | * "auto" will automatically assign a view-transition-name to the inner DOM node.
|
151 | * That way you can add a View Transition to a Component without controlling its DOM nodes styling otherwise.
|
152 | *
|
153 | * A difference between this and the browser's built-in view-transition-name: auto is that switching the DOM nodes within the `<ViewTransition>` component preserves the same name so this example cross-fades between the DOM nodes instead of causing an exit and enter.
|
154 | * @default "auto"
|
155 | */
|
156 | name?: "auto" | (string & {}) | undefined;
|
157 | /**
|
158 | * The `<ViewTransition>` or its parent Component is mounted and there's no other `<ViewTransition>` with the same name being deleted.
|
159 | */
|
160 | onEnter?: (instance: ViewTransitionInstance) => void;
|
161 | /**
|
162 | * The `<ViewTransition>` or its parent Component is unmounted and there's no other `<ViewTransition>` with the same name being deleted.
|
163 | */
|
164 | onExit?: (instance: ViewTransitionInstance) => void;
|
165 | /**
|
166 | * There are no updates to the content inside this `<ViewTransition>` boundary itself but the boundary has resized or moved due to other changes to siblings.
|
167 | */
|
168 | onLayout?: (instance: ViewTransitionInstance) => void;
|
169 | /**
|
170 | * This `<ViewTransition>` is being mounted and another `<ViewTransition>` instance with the same name is being unmounted elsewhere.
|
171 | */
|
172 | onShare?: (instance: ViewTransitionInstance) => void;
|
173 | /**
|
174 | * The content of `<ViewTransition>` has changed either due to DOM mutations or because an inner child `<ViewTransition>` has resized.
|
175 | */
|
176 | onUpdate?: (instance: ViewTransitionInstance) => void;
|
177 | ref?: Ref<ViewTransitionInstance> | undefined;
|
178 | /**
|
179 | * Combined with {@link className} if this `<ViewTransition>` is being mounted and another instance with the same name is being unmounted elsewhere.
|
180 | * `"none"` is a special value that deactivates the view transition name under that condition.
|
181 | */
|
182 | share?: "none" | (string & {}) | undefined;
|
183 | /**
|
184 | * Combined with {@link className} if the content of this `<ViewTransition>` has changed either due to DOM mutations or because an inner child has resized.
|
185 | * `"none"` is a special value that deactivates the view transition name under that condition.
|
186 | */
|
187 | update?: "none" | (string & {}) | undefined;
|
188 | }
|
189 |
|
190 | /**
|
191 | * Opt-in for using {@link https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API View Transitions} in React.
|
192 | * View Transitions only trigger for async updates like {@link startTransition}, {@link useDeferredValue}, Actions or <{@link Suspense}> revealing from fallback to content.
|
193 | * Synchronous updates provide an opt-out but also guarantee that they commit immediately which View Transitions can't.
|
194 | *
|
195 | * @see {@link https://github.com/facebook/react/pull/31975}
|
196 | */
|
197 | export const unstable_ViewTransition: ExoticComponent<ViewTransitionProps>;
|
198 |
|
199 | // Implemented by the specific renderer e.g. `react-dom`.
|
200 | // Keep in mind that augmented interfaces merge their JSDoc so if you put
|
201 | // JSDoc here and in the renderer, the IDE will display both.
|
202 | export interface GestureProvider {}
|
203 |
|
204 | export type StartGesture = (gestureProvider: GestureProvider) => () => void;
|
205 |
|
206 | /** */
|
207 | export function unstable_useSwipeTransition<Value>(
|
208 | previous: Value,
|
209 | current: Value,
|
210 | next: Value,
|
211 | ): [value: Value, startGesture: StartGesture];
|
212 | }
|