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/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/next'
|
15 | * ```
|
16 | *
|
17 | * It is also possible to include it through a triple-slash reference:
|
18 | *
|
19 | * ```ts
|
20 | * /// <reference types="react/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/src/React.js to see how the exports are declared,
|
27 |
|
28 | import React = require('.');
|
29 |
|
30 | export {};
|
31 |
|
32 | declare const UNDEFINED_VOID_ONLY: unique symbol;
|
33 | type VoidOrUndefinedOnly = void | { [UNDEFINED_VOID_ONLY]: never };
|
34 |
|
35 | declare module '.' {
|
36 | export interface SuspenseProps {
|
37 | /**
|
38 | * The presence of this prop indicates that the content is computationally expensive to render.
|
39 | * In other words, the tree is CPU bound and not I/O bound (e.g. due to fetching data).
|
40 | * @see {@link https://github.com/facebook/react/pull/19936}
|
41 | */
|
42 | unstable_expectedLoadTime?: number | undefined;
|
43 | }
|
44 |
|
45 | // must be synchronous
|
46 | export type TransitionFunction = () => VoidOrUndefinedOnly;
|
47 | // strange definition to allow vscode to show documentation on the invocation
|
48 | export interface TransitionStartFunction {
|
49 | /**
|
50 | * State updates caused inside the callback are allowed to be deferred.
|
51 | *
|
52 | * **If some state update causes a component to suspend, that state update should be wrapped in a transition.**
|
53 | *
|
54 | * @param callback A _synchronous_ function which causes state updates that can be deferred.
|
55 | */
|
56 | (callback: TransitionFunction): void;
|
57 | }
|
58 |
|
59 | /**
|
60 | * Returns a deferred version of the value that may “lag behind” it for at most `timeoutMs`.
|
61 | *
|
62 | * This is commonly used to keep the interface responsive when you have something that renders immediately
|
63 | * based on user input and something that needs to wait for a data fetch.
|
64 | *
|
65 | * A good example of this is a text input.
|
66 | *
|
67 | * @param value The value that is going to be deferred
|
68 | *
|
69 | * @see https://reactjs.org/docs/concurrent-mode-reference.html#usedeferredvalue
|
70 | */
|
71 | export function useDeferredValue<T>(value: T): T;
|
72 |
|
73 | /**
|
74 | * Allows components to avoid undesirable loading states by waiting for content to load
|
75 | * before transitioning to the next screen. It also allows components to defer slower,
|
76 | * data fetching updates until subsequent renders so that more crucial updates can be
|
77 | * rendered immediately.
|
78 | *
|
79 | * The `useTransition` hook returns two values in an array.
|
80 | *
|
81 | * The first is a boolean, React’s way of informing us whether we’re waiting for the transition to finish.
|
82 | * The second is a function that takes a callback. We can use it to tell React which state we want to defer.
|
83 | *
|
84 | * **If some state update causes a component to suspend, that state update should be wrapped in a transition.**
|
85 | *
|
86 | * @param config An optional object with `timeoutMs`
|
87 | *
|
88 | * @see https://reactjs.org/docs/concurrent-mode-reference.html#usetransition
|
89 | */
|
90 | export function useTransition(): [boolean, TransitionStartFunction];
|
91 |
|
92 | /**
|
93 | * Similar to `useTransition` but allows uses where hooks are not available.
|
94 | *
|
95 | * @param callback A _synchronous_ function which causes state updates that can be deferred.
|
96 | */
|
97 | export function startTransition(scope: TransitionFunction): void;
|
98 |
|
99 | export function useId(): string;
|
100 |
|
101 | /**
|
102 | * this should be an internal type
|
103 | */
|
104 | interface MutableSource<T> {
|
105 | _source: T;
|
106 | }
|
107 |
|
108 | export type MutableSourceSubscribe<T> = (source: T, callback: () => void) => () => void;
|
109 |
|
110 | /**
|
111 | * @param source A source could be anything as long as they can be subscribed to and have a "version".
|
112 | * @param getVersion A function returns a value which will change whenever part of the source changes.
|
113 | */
|
114 | export function unstable_createMutableSource<T>(source: T, getVersion: () => any): MutableSource<T>;
|
115 |
|
116 | /**
|
117 | * useMutableSource() enables React components to safely and efficiently read from a mutable external source in Concurrent Mode.
|
118 | * The API will detect mutations that occur during a render to avoid tearing
|
119 | * and it will automatically schedule updates when the source is mutated.
|
120 | * @param MutableSource
|
121 | * @param getSnapshot
|
122 | * @param subscribe
|
123 | *
|
124 | * @see https://github.com/reactjs/rfcs/blob/master/text/0147-use-mutable-source.md
|
125 | */
|
126 | export function unstable_useMutableSource<T, TResult extends unknown>(MutableSource: MutableSource<T>, getSnapshot: (source: T) => TResult, subscribe: MutableSourceSubscribe<T>): TResult;
|
127 |
|
128 | /**
|
129 | * @param effect Imperative function that can return a cleanup function
|
130 | * @param deps If present, effect will only activate if the values in the list change.
|
131 | *
|
132 | * @see https://github.com/facebook/react/pull/21913
|
133 | */
|
134 | export function useInsertionEffect(effect: EffectCallback, deps?: DependencyList): void;
|
135 |
|
136 | /**
|
137 | * @param subscribe
|
138 | * @param getSnapshot
|
139 | *
|
140 | * @see https://github.com/reactwg/react-18/discussions/86
|
141 | */
|
142 | // keep in sync with `useSyncExternalStore` from `use-sync-external-store`
|
143 | export function useSyncExternalStore<Snapshot>(
|
144 | subscribe: (onStoreChange: () => void) => () => void,
|
145 | getSnapshot: () => Snapshot,
|
146 | getServerSnapshot?: () => Snapshot,
|
147 | ): Snapshot;
|
148 | }
|