@types/react 18.2.52 → 18.2.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- react/README.md +1 -1
- react/index.d.ts +133 -61
- react/package.json +2 -2
- react/ts5.0/index.d.ts +857 -129
react/ts5.0/index.d.ts
CHANGED
@@ -20,11 +20,26 @@ type NativePointerEvent = PointerEvent;
|
|
20
20
|
type NativeTransitionEvent = TransitionEvent;
|
21
21
|
type NativeUIEvent = UIEvent;
|
22
22
|
type NativeWheelEvent = WheelEvent;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Used to represent DOM API's where users can either pass
|
26
|
+
* true or false as a boolean or as its equivalent strings.
|
27
|
+
*/
|
23
28
|
type Booleanish = boolean | "true" | "false";
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin MDN}
|
32
|
+
*/
|
24
33
|
type CrossOrigin = "anonymous" | "use-credentials" | "" | undefined;
|
25
34
|
|
26
35
|
declare const UNDEFINED_VOID_ONLY: unique symbol;
|
27
|
-
|
36
|
+
|
37
|
+
/**
|
38
|
+
* The function returned from an effect passed to {@link React.useEffect useEffect},
|
39
|
+
* which can be used to clean up the effect when the component unmounts.
|
40
|
+
*
|
41
|
+
* @see {@link https://react.dev/reference/react/useEffect React Docs}
|
42
|
+
*/
|
28
43
|
type Destructor = () => void | { [UNDEFINED_VOID_ONLY]: never };
|
29
44
|
type VoidOrUndefinedOnly = void | { [UNDEFINED_VOID_ONLY]: never };
|
30
45
|
|
@@ -37,52 +52,158 @@ declare namespace React {
|
|
37
52
|
// React Elements
|
38
53
|
// ----------------------------------------------------------------------
|
39
54
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
55
|
+
/**
|
56
|
+
* Used to retrieve the possible components which accept a given set of props.
|
57
|
+
*
|
58
|
+
* Can be passed no type parameters to get a union of all possible components
|
59
|
+
* and tags.
|
60
|
+
*
|
61
|
+
* Is a superset of {@link ComponentType}.
|
62
|
+
*
|
63
|
+
* @template P The props to match against. If not passed, defaults to any.
|
64
|
+
* @template Tag An optional tag to match against. If not passed, attempts to match against all possible tags.
|
65
|
+
*
|
66
|
+
* @example
|
67
|
+
*
|
68
|
+
* ```tsx
|
69
|
+
* // All components and tags (img, embed etc.)
|
70
|
+
* // which accept `src`
|
71
|
+
* type SrcComponents = ElementType<{ src: any }>;
|
72
|
+
* ```
|
73
|
+
*
|
74
|
+
* @example
|
75
|
+
*
|
76
|
+
* ```tsx
|
77
|
+
* // All components
|
78
|
+
* type AllComponents = ElementType;
|
79
|
+
* ```
|
80
|
+
*
|
81
|
+
* @example
|
82
|
+
*
|
83
|
+
* ```tsx
|
84
|
+
* // All custom components which match `src`, and tags which
|
85
|
+
* // match `src`, narrowed down to just `audio` and `embed`
|
86
|
+
* type SrcComponents = ElementType<{ src: any }, 'audio' | 'embed'>;
|
87
|
+
* ```
|
88
|
+
*/
|
89
|
+
type ElementType<P = any, Tag extends keyof JSX.IntrinsicElements = keyof JSX.IntrinsicElements> =
|
90
|
+
| { [K in Tag]: P extends JSX.IntrinsicElements[K] ? K : never }[Tag]
|
44
91
|
| ComponentType<P>;
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Represents any user-defined component, either as a function component or
|
95
|
+
* a class component.
|
96
|
+
*
|
97
|
+
* @template P The props the component accepts.
|
98
|
+
*
|
99
|
+
* @see {@link ComponentClass}
|
100
|
+
* @see {@link FunctionComponent}
|
101
|
+
*/
|
45
102
|
type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
|
46
103
|
|
104
|
+
/**
|
105
|
+
* Represents any user-defined component, either as a function or a class.
|
106
|
+
*
|
107
|
+
* Similar to {@link ComponentType}, but without extra properties like
|
108
|
+
* {@link FunctionComponent.defaultProps defaultProps } and
|
109
|
+
* {@link ComponentClass.contextTypes contextTypes}.
|
110
|
+
*
|
111
|
+
* @template P The props the component accepts.
|
112
|
+
*/
|
47
113
|
type JSXElementConstructor<P> =
|
48
114
|
| ((
|
49
115
|
props: P,
|
50
116
|
/**
|
51
|
-
* @deprecated
|
117
|
+
* @deprecated
|
118
|
+
*
|
119
|
+
* @see {@link https://legacy.reactjs.org/docs/legacy-context.html#referencing-context-in-stateless-function-components React Docs}
|
52
120
|
*/
|
53
121
|
deprecatedLegacyContext?: any,
|
54
122
|
) => ReactElement<any, any> | null)
|
55
123
|
| (new(
|
56
124
|
props: P,
|
57
125
|
/**
|
58
|
-
* @deprecated
|
126
|
+
* @deprecated
|
127
|
+
*
|
128
|
+
* @see {@link https://legacy.reactjs.org/docs/legacy-context.html#referencing-context-in-lifecycle-methods React Docs}
|
59
129
|
*/
|
60
130
|
deprecatedLegacyContext?: any,
|
61
131
|
) => Component<any, any>);
|
62
132
|
|
133
|
+
/**
|
134
|
+
* A readonly ref container where {@link current} cannot be mutated.
|
135
|
+
*
|
136
|
+
* Created by {@link createRef}, or {@link useRef} when passed `null`.
|
137
|
+
*
|
138
|
+
* @template T The type of the ref's value.
|
139
|
+
*
|
140
|
+
* @example
|
141
|
+
*
|
142
|
+
* ```tsx
|
143
|
+
* const ref = createRef<HTMLDivElement>();
|
144
|
+
*
|
145
|
+
* ref.current = document.createElement('div'); // Error
|
146
|
+
* ```
|
147
|
+
*/
|
63
148
|
interface RefObject<T> {
|
149
|
+
/**
|
150
|
+
* The current value of the ref.
|
151
|
+
*/
|
64
152
|
readonly current: T | null;
|
65
153
|
}
|
66
|
-
|
154
|
+
|
155
|
+
/**
|
156
|
+
* A callback fired whenever the ref's value changes.
|
157
|
+
*
|
158
|
+
* @template T The type of the ref's value.
|
159
|
+
*
|
160
|
+
* @see {@link https://react.dev/reference/react-dom/components/common#ref-callback React Docs}
|
161
|
+
*
|
162
|
+
* @example
|
163
|
+
*
|
164
|
+
* ```tsx
|
165
|
+
* <div ref={(node) => console.log(node)} />
|
166
|
+
* ```
|
167
|
+
*/
|
67
168
|
type RefCallback<T> = { bivarianceHack(instance: T | null): void }["bivarianceHack"];
|
169
|
+
|
170
|
+
/**
|
171
|
+
* A union type of all possible shapes for React refs.
|
172
|
+
*
|
173
|
+
* @see {@link RefCallback}
|
174
|
+
* @see {@link RefObject}
|
175
|
+
*/
|
176
|
+
|
68
177
|
type Ref<T> = RefCallback<T> | RefObject<T> | null;
|
178
|
+
/**
|
179
|
+
* A legacy implementation of refs where you can pass a string to a ref prop.
|
180
|
+
*
|
181
|
+
* @see {@link https://react.dev/reference/react/Component#refs React Docs}
|
182
|
+
*
|
183
|
+
* @example
|
184
|
+
*
|
185
|
+
* ```tsx
|
186
|
+
* <div ref="myRef" />
|
187
|
+
* ```
|
188
|
+
*/
|
69
189
|
type LegacyRef<T> = string | Ref<T>;
|
190
|
+
|
70
191
|
/**
|
71
|
-
*
|
192
|
+
* Retrieves the type of the 'ref' prop for a given component type or tag name.
|
72
193
|
*
|
73
|
-
*
|
74
|
-
* and used `React.ElementRef<typeof Foo>` then the type would be the instance of `Foo`.
|
75
|
-
* - React stateless functional components do not have a backing instance and so `React.ElementRef<typeof Bar>`
|
76
|
-
* (when `Bar` is `function Bar() {}`) will give you the `undefined` type.
|
77
|
-
* - JSX intrinsics like `div` will give you their DOM instance. For `React.ElementRef<'div'>` that would be
|
78
|
-
* `HTMLDivElement`. For `React.ElementRef<'input'>` that would be `HTMLInputElement`.
|
79
|
-
* - React stateless functional components that forward a `ref` will give you the `ElementRef` of the forwarded
|
80
|
-
* to component.
|
194
|
+
* @template C The component type.
|
81
195
|
*
|
82
|
-
*
|
196
|
+
* @example
|
83
197
|
*
|
84
|
-
*
|
85
|
-
*
|
198
|
+
* ```tsx
|
199
|
+
* type MyComponentRef = React.ElementRef<typeof MyComponent>;
|
200
|
+
* ```
|
201
|
+
*
|
202
|
+
* @example
|
203
|
+
*
|
204
|
+
* ```tsx
|
205
|
+
* type DivRef = React.ElementRef<'div'>;
|
206
|
+
* ```
|
86
207
|
*/
|
87
208
|
type ElementRef<
|
88
209
|
C extends
|
@@ -101,6 +222,11 @@ declare namespace React {
|
|
101
222
|
|
102
223
|
type ComponentState = any;
|
103
224
|
|
225
|
+
/**
|
226
|
+
* A value which uniquely identifies a node among items in an array.
|
227
|
+
*
|
228
|
+
* @see {@link https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key React Docs}
|
229
|
+
*/
|
104
230
|
type Key = string | number | bigint;
|
105
231
|
|
106
232
|
/**
|
@@ -114,15 +240,18 @@ declare namespace React {
|
|
114
240
|
/**
|
115
241
|
* Allows getting a ref to the component instance.
|
116
242
|
* Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref).
|
117
|
-
* @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom
|
243
|
+
* @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom}
|
118
244
|
*/
|
119
245
|
ref?: Ref<T> | undefined;
|
120
246
|
}
|
247
|
+
/**
|
248
|
+
* Represents the built-in attributes available to class components.
|
249
|
+
*/
|
121
250
|
interface ClassAttributes<T> extends Attributes {
|
122
251
|
/**
|
123
252
|
* Allows getting a ref to the component instance.
|
124
253
|
* Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref).
|
125
|
-
* @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom
|
254
|
+
* @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom}
|
126
255
|
*/
|
127
256
|
ref?: LegacyRef<T> | undefined;
|
128
257
|
}
|
@@ -150,6 +279,9 @@ declare namespace React {
|
|
150
279
|
ref?: LegacyRef<T> | undefined;
|
151
280
|
}
|
152
281
|
|
282
|
+
/**
|
283
|
+
* @deprecated Use `ComponentElement<P, ClassicComponent<P, any>>` instead.
|
284
|
+
*/
|
153
285
|
type ClassicElement<P> = CElement<P, ClassicComponent<P, ComponentState>>;
|
154
286
|
|
155
287
|
// string fallback for custom web-components
|
@@ -242,6 +374,34 @@ declare namespace React {
|
|
242
374
|
* App or library types should never augment this interface.
|
243
375
|
*/
|
244
376
|
interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_REACT_NODES {}
|
377
|
+
|
378
|
+
/**
|
379
|
+
* Represents all of the things React can render.
|
380
|
+
*
|
381
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/react-types/reactnode/ React TypeScript Cheatsheet}
|
382
|
+
*
|
383
|
+
* @example
|
384
|
+
*
|
385
|
+
* ```tsx
|
386
|
+
* // Typing children
|
387
|
+
* type Props = { children: ReactNode }
|
388
|
+
*
|
389
|
+
* const Component = ({ children }: Props) => <div>{children}</div>
|
390
|
+
*
|
391
|
+
* <Component>hello</Component>
|
392
|
+
* ```
|
393
|
+
*
|
394
|
+
* @example
|
395
|
+
*
|
396
|
+
* ```tsx
|
397
|
+
* // Typing a custom element
|
398
|
+
* type Props = { customElement: ReactNode }
|
399
|
+
*
|
400
|
+
* const Component = ({ customElement }: Props) => <div>{customElement}</div>
|
401
|
+
*
|
402
|
+
* <Component customElement={<div>hello</div>} />
|
403
|
+
* ```
|
404
|
+
*/
|
245
405
|
type ReactNode =
|
246
406
|
| ReactElement
|
247
407
|
| string
|
@@ -272,9 +432,6 @@ declare namespace React {
|
|
272
432
|
|
273
433
|
// Custom components
|
274
434
|
function createFactory<P>(type: FunctionComponent<P>): FunctionComponentFactory<P>;
|
275
|
-
function createFactory<P>(
|
276
|
-
type: ClassType<P, ClassicComponent<P, ComponentState>, ClassicComponentClass<P>>,
|
277
|
-
): CFactory<P, ClassicComponent<P, ComponentState>>;
|
278
435
|
function createFactory<P, T extends Component<P, ComponentState>, C extends ComponentClass<P>>(
|
279
436
|
type: ClassType<P, T, C>,
|
280
437
|
): CFactory<P, T>;
|
@@ -310,11 +467,6 @@ declare namespace React {
|
|
310
467
|
props?: Attributes & P | null,
|
311
468
|
...children: ReactNode[]
|
312
469
|
): FunctionComponentElement<P>;
|
313
|
-
function createElement<P extends {}>(
|
314
|
-
type: ClassType<P, ClassicComponent<P, ComponentState>, ClassicComponentClass<P>>,
|
315
|
-
props?: ClassAttributes<ClassicComponent<P, ComponentState>> & P | null,
|
316
|
-
...children: ReactNode[]
|
317
|
-
): CElement<P, ClassicComponent<P, ComponentState>>;
|
318
470
|
function createElement<P extends {}, T extends Component<P, ComponentState>, C extends ComponentClass<P>>(
|
319
471
|
type: ClassType<P, T, C>,
|
320
472
|
props?: ClassAttributes<T> & P | null,
|
@@ -369,53 +521,169 @@ declare namespace React {
|
|
369
521
|
...children: ReactNode[]
|
370
522
|
): ReactElement<P>;
|
371
523
|
|
372
|
-
|
524
|
+
/**
|
525
|
+
* Describes the props accepted by a Context {@link Provider}.
|
526
|
+
*
|
527
|
+
* @template T The type of the value the context provides.
|
528
|
+
*/
|
373
529
|
interface ProviderProps<T> {
|
374
530
|
value: T;
|
375
531
|
children?: ReactNode | undefined;
|
376
532
|
}
|
377
533
|
|
534
|
+
/**
|
535
|
+
* Describes the props accepted by a Context {@link Consumer}.
|
536
|
+
*
|
537
|
+
* @template T The type of the value the context provides.
|
538
|
+
*/
|
378
539
|
interface ConsumerProps<T> {
|
379
540
|
children: (value: T) => ReactNode;
|
380
541
|
}
|
381
542
|
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
543
|
+
/**
|
544
|
+
* An object masquerading as a component. These are created by functions
|
545
|
+
* like {@link forwardRef}, {@link memo}, and {@link createContext}.
|
546
|
+
*
|
547
|
+
* In order to make TypeScript work, we pretend that they are normal
|
548
|
+
* components.
|
549
|
+
*
|
550
|
+
* But they are, in fact, not callable - instead, they are objects which
|
551
|
+
* are treated specially by the renderer.
|
552
|
+
*/
|
392
553
|
interface ExoticComponent<P = {}> {
|
393
|
-
/**
|
394
|
-
* **NOTE**: Exotic components are not callable.
|
395
|
-
*/
|
396
554
|
(props: P): ReactElement | null;
|
397
555
|
readonly $$typeof: symbol;
|
398
556
|
}
|
399
557
|
|
558
|
+
/**
|
559
|
+
* An {@link ExoticComponent} with a `displayName` property applied to it.
|
560
|
+
*/
|
400
561
|
interface NamedExoticComponent<P = {}> extends ExoticComponent<P> {
|
562
|
+
/**
|
563
|
+
* Used in debugging messages. You might want to set it
|
564
|
+
* explicitly if you want to display a different name for
|
565
|
+
* debugging purposes.
|
566
|
+
*
|
567
|
+
* @see {@link https://legacy.reactjs.org/docs/react-component.html#displayname Legacy React Docs}
|
568
|
+
*/
|
401
569
|
displayName?: string | undefined;
|
402
570
|
}
|
403
571
|
|
572
|
+
/**
|
573
|
+
* An {@link ExoticComponent} with a `propTypes` property applied to it.
|
574
|
+
*/
|
404
575
|
interface ProviderExoticComponent<P> extends ExoticComponent<P> {
|
405
576
|
propTypes?: WeakValidationMap<P> | undefined;
|
406
577
|
}
|
407
578
|
|
579
|
+
/**
|
580
|
+
* Used to retrieve the type of a context object from a {@link Context}.
|
581
|
+
*
|
582
|
+
* @example
|
583
|
+
*
|
584
|
+
* ```tsx
|
585
|
+
* import { createContext } from 'react';
|
586
|
+
*
|
587
|
+
* const MyContext = createContext({ foo: 'bar' });
|
588
|
+
*
|
589
|
+
* type ContextType = ContextType<typeof MyContext>;
|
590
|
+
* // ContextType = { foo: string }
|
591
|
+
* ```
|
592
|
+
*/
|
408
593
|
type ContextType<C extends Context<any>> = C extends Context<infer T> ? T : never;
|
409
594
|
|
410
|
-
|
411
|
-
|
595
|
+
/**
|
596
|
+
* Wraps your components to specify the value of this context for all components inside.
|
597
|
+
*
|
598
|
+
* @see {@link https://react.dev/reference/react/createContext#provider React Docs}
|
599
|
+
*
|
600
|
+
* @example
|
601
|
+
*
|
602
|
+
* ```tsx
|
603
|
+
* import { createContext } from 'react';
|
604
|
+
*
|
605
|
+
* const ThemeContext = createContext('light');
|
606
|
+
*
|
607
|
+
* function App() {
|
608
|
+
* return (
|
609
|
+
* <ThemeContext.Provider value="dark">
|
610
|
+
* <Toolbar />
|
611
|
+
* </ThemeContext.Provider>
|
612
|
+
* );
|
613
|
+
* }
|
614
|
+
* ```
|
615
|
+
*/
|
412
616
|
type Provider<T> = ProviderExoticComponent<ProviderProps<T>>;
|
617
|
+
|
618
|
+
/**
|
619
|
+
* The old way to read context, before {@link useContext} existed.
|
620
|
+
*
|
621
|
+
* @see {@link https://react.dev/reference/react/createContext#consumer React Docs}
|
622
|
+
*
|
623
|
+
* @example
|
624
|
+
*
|
625
|
+
* ```tsx
|
626
|
+
* import { UserContext } from './user-context';
|
627
|
+
*
|
628
|
+
* function Avatar() {
|
629
|
+
* return (
|
630
|
+
* <UserContext.Consumer>
|
631
|
+
* {user => <img src={user.profileImage} alt={user.name} />}
|
632
|
+
* </UserContext.Consumer>
|
633
|
+
* );
|
634
|
+
* }
|
635
|
+
* ```
|
636
|
+
*/
|
413
637
|
type Consumer<T> = ExoticComponent<ConsumerProps<T>>;
|
638
|
+
|
639
|
+
/**
|
640
|
+
* Context lets components pass information deep down without explicitly
|
641
|
+
* passing props.
|
642
|
+
*
|
643
|
+
* Created from {@link createContext}
|
644
|
+
*
|
645
|
+
* @see {@link https://react.dev/learn/passing-data-deeply-with-context React Docs}
|
646
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/context/ React TypeScript Cheatsheet}
|
647
|
+
*
|
648
|
+
* @example
|
649
|
+
*
|
650
|
+
* ```tsx
|
651
|
+
* import { createContext } from 'react';
|
652
|
+
*
|
653
|
+
* const ThemeContext = createContext('light');
|
654
|
+
* ```
|
655
|
+
*/
|
414
656
|
interface Context<T> {
|
415
657
|
Provider: Provider<T>;
|
416
658
|
Consumer: Consumer<T>;
|
659
|
+
/**
|
660
|
+
* Used in debugging messages. You might want to set it
|
661
|
+
* explicitly if you want to display a different name for
|
662
|
+
* debugging purposes.
|
663
|
+
*
|
664
|
+
* @see {@link https://legacy.reactjs.org/docs/react-component.html#displayname Legacy React Docs}
|
665
|
+
*/
|
417
666
|
displayName?: string | undefined;
|
418
667
|
}
|
668
|
+
|
669
|
+
/**
|
670
|
+
* Lets you create a {@link Context} that components can provide or read.
|
671
|
+
*
|
672
|
+
* @param defaultValue The value you want the context to have when there is no matching
|
673
|
+
* {@link Provider} in the tree above the component reading the context. This is meant
|
674
|
+
* as a "last resort" fallback.
|
675
|
+
*
|
676
|
+
* @see {@link https://react.dev/reference/react/createContext#reference React Docs}
|
677
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/context/ React TypeScript Cheatsheet}
|
678
|
+
*
|
679
|
+
* @example
|
680
|
+
*
|
681
|
+
* ```tsx
|
682
|
+
* import { createContext } from 'react';
|
683
|
+
*
|
684
|
+
* const ThemeContext = createContext('light');
|
685
|
+
* ```
|
686
|
+
*/
|
419
687
|
function createContext<T>(
|
420
688
|
// If you thought this should be optional, see
|
421
689
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/24509#issuecomment-382213106
|
@@ -424,7 +692,9 @@ declare namespace React {
|
|
424
692
|
|
425
693
|
function isValidElement<P>(object: {} | null | undefined): object is ReactElement<P>;
|
426
694
|
|
427
|
-
|
695
|
+
/**
|
696
|
+
* Maintainer's note: Sync with {@link ReactChildren} until {@link ReactChildren} is removed.
|
697
|
+
*/
|
428
698
|
const Children: {
|
429
699
|
map<T, C>(
|
430
700
|
children: C | readonly C[],
|
@@ -435,9 +705,57 @@ declare namespace React {
|
|
435
705
|
only<C>(children: C): C extends any[] ? never : C;
|
436
706
|
toArray(children: ReactNode | ReactNode[]): Array<Exclude<ReactNode, boolean | null | undefined>>;
|
437
707
|
};
|
708
|
+
/**
|
709
|
+
* Lets you group elements without a wrapper node.
|
710
|
+
*
|
711
|
+
* @see {@link https://react.dev/reference/react/Fragment React Docs}
|
712
|
+
*
|
713
|
+
* @example
|
714
|
+
*
|
715
|
+
* ```tsx
|
716
|
+
* import { Fragment } from 'react';
|
717
|
+
*
|
718
|
+
* <Fragment>
|
719
|
+
* <td>Hello</td>
|
720
|
+
* <td>World</td>
|
721
|
+
* </Fragment>
|
722
|
+
* ```
|
723
|
+
*
|
724
|
+
* @example
|
725
|
+
*
|
726
|
+
* ```tsx
|
727
|
+
* // Using the <></> shorthand syntax:
|
728
|
+
*
|
729
|
+
* <>
|
730
|
+
* <td>Hello</td>
|
731
|
+
* <td>World</td>
|
732
|
+
* </>
|
733
|
+
* ```
|
734
|
+
*/
|
438
735
|
const Fragment: ExoticComponent<{ children?: ReactNode | undefined }>;
|
736
|
+
|
737
|
+
/**
|
738
|
+
* Lets you find common bugs in your components early during development.
|
739
|
+
*
|
740
|
+
* @see {@link https://react.dev/reference/react/StrictMode React Docs}
|
741
|
+
*
|
742
|
+
* @example
|
743
|
+
*
|
744
|
+
* ```tsx
|
745
|
+
* import { StrictMode } from 'react';
|
746
|
+
*
|
747
|
+
* <StrictMode>
|
748
|
+
* <App />
|
749
|
+
* </StrictMode>
|
750
|
+
* ```
|
751
|
+
*/
|
439
752
|
const StrictMode: ExoticComponent<{ children?: ReactNode | undefined }>;
|
440
753
|
|
754
|
+
/**
|
755
|
+
* The props accepted by {@link Suspense}.
|
756
|
+
*
|
757
|
+
* @see {@link https://react.dev/reference/react/Suspense React Docs}
|
758
|
+
*/
|
441
759
|
interface SuspenseProps {
|
442
760
|
children?: ReactNode | undefined;
|
443
761
|
|
@@ -445,27 +763,105 @@ declare namespace React {
|
|
445
763
|
fallback?: ReactNode;
|
446
764
|
}
|
447
765
|
|
766
|
+
/**
|
767
|
+
* Lets you display a fallback until its children have finished loading.
|
768
|
+
*
|
769
|
+
* @see {@link https://react.dev/reference/react/Suspense React Docs}
|
770
|
+
*
|
771
|
+
* @example
|
772
|
+
*
|
773
|
+
* ```tsx
|
774
|
+
* import { Suspense } from 'react';
|
775
|
+
*
|
776
|
+
* <Suspense fallback={<Loading />}>
|
777
|
+
* <ProfileDetails />
|
778
|
+
* </Suspense>
|
779
|
+
* ```
|
780
|
+
*/
|
448
781
|
const Suspense: ExoticComponent<SuspenseProps>;
|
449
782
|
const version: string;
|
450
783
|
|
451
784
|
/**
|
452
|
-
* {@link
|
785
|
+
* The callback passed to {@link ProfilerProps.onRender}.
|
786
|
+
*
|
787
|
+
* @see {@link https://react.dev/reference/react/Profiler#onrender-callback React Docs}
|
453
788
|
*/
|
454
789
|
type ProfilerOnRenderCallback = (
|
790
|
+
/**
|
791
|
+
* The string id prop of the {@link Profiler} tree that has just committed. This lets
|
792
|
+
* you identify which part of the tree was committed if you are using multiple
|
793
|
+
* profilers.
|
794
|
+
*
|
795
|
+
* @see {@link https://react.dev/reference/react/Profiler#onrender-callback React Docs}
|
796
|
+
*/
|
455
797
|
id: string,
|
798
|
+
/**
|
799
|
+
* This lets you know whether the tree has just been mounted for the first time
|
800
|
+
* or re-rendered due to a change in props, state, or hooks.
|
801
|
+
*
|
802
|
+
* @see {@link https://react.dev/reference/react/Profiler#onrender-callback React Docs}
|
803
|
+
*/
|
456
804
|
phase: "mount" | "update" | "nested-update",
|
805
|
+
/**
|
806
|
+
* The number of milliseconds spent rendering the {@link Profiler} and its descendants
|
807
|
+
* for the current update. This indicates how well the subtree makes use of
|
808
|
+
* memoization (e.g. {@link memo} and {@link useMemo}). Ideally this value should decrease
|
809
|
+
* significantly after the initial mount as many of the descendants will only need to
|
810
|
+
* re-render if their specific props change.
|
811
|
+
*
|
812
|
+
* @see {@link https://react.dev/reference/react/Profiler#onrender-callback React Docs}
|
813
|
+
*/
|
457
814
|
actualDuration: number,
|
815
|
+
/**
|
816
|
+
* The number of milliseconds estimating how much time it would take to re-render the entire
|
817
|
+
* {@link Profiler} subtree without any optimizations. It is calculated by summing up the most
|
818
|
+
* recent render durations of each component in the tree. This value estimates a worst-case
|
819
|
+
* cost of rendering (e.g. the initial mount or a tree with no memoization). Compare
|
820
|
+
* {@link actualDuration} against it to see if memoization is working.
|
821
|
+
*
|
822
|
+
* @see {@link https://react.dev/reference/react/Profiler#onrender-callback React Docs}
|
823
|
+
*/
|
458
824
|
baseDuration: number,
|
825
|
+
/**
|
826
|
+
* A numeric timestamp for when React began rendering the current update.
|
827
|
+
*
|
828
|
+
* @see {@link https://react.dev/reference/react/Profiler#onrender-callback React Docs}
|
829
|
+
*/
|
459
830
|
startTime: number,
|
831
|
+
/**
|
832
|
+
* A numeric timestamp for when React committed the current update. This value is shared
|
833
|
+
* between all profilers in a commit, enabling them to be grouped if desirable.
|
834
|
+
*
|
835
|
+
* @see {@link https://react.dev/reference/react/Profiler#onrender-callback React Docs}
|
836
|
+
*/
|
460
837
|
commitTime: number,
|
461
838
|
interactions: Set<SchedulerInteraction>,
|
462
839
|
) => void;
|
840
|
+
|
841
|
+
/**
|
842
|
+
* The props accepted by {@link Profiler}.
|
843
|
+
*
|
844
|
+
* @see {@link https://react.dev/reference/react/Profiler React Docs}
|
845
|
+
*/
|
463
846
|
interface ProfilerProps {
|
464
847
|
children?: ReactNode | undefined;
|
465
848
|
id: string;
|
466
849
|
onRender: ProfilerOnRenderCallback;
|
467
850
|
}
|
468
851
|
|
852
|
+
/**
|
853
|
+
* Lets you measure rendering performance of a React tree programmatically.
|
854
|
+
*
|
855
|
+
* @see {@link https://react.dev/reference/react/Profiler#onrender-callback React Docs}
|
856
|
+
*
|
857
|
+
* @example
|
858
|
+
*
|
859
|
+
* ```tsx
|
860
|
+
* <Profiler id="App" onRender={onRender}>
|
861
|
+
* <App />
|
862
|
+
* </Profiler>
|
863
|
+
* ```
|
864
|
+
*/
|
469
865
|
const Profiler: ExoticComponent<ProfilerProps>;
|
470
866
|
|
471
867
|
//
|
@@ -481,7 +877,7 @@ declare namespace React {
|
|
481
877
|
/**
|
482
878
|
* If set, `this.context` will be set at runtime to the current value of the given Context.
|
483
879
|
*
|
484
|
-
*
|
880
|
+
* @example
|
485
881
|
*
|
486
882
|
* ```ts
|
487
883
|
* type MyContext = number
|
@@ -496,7 +892,7 @@ declare namespace React {
|
|
496
892
|
* }
|
497
893
|
* ```
|
498
894
|
*
|
499
|
-
* @see https://react.dev/reference/react/Component#static-contexttype
|
895
|
+
* @see {@link https://react.dev/reference/react/Component#static-contexttype}
|
500
896
|
*/
|
501
897
|
static contextType?: Context<any> | undefined;
|
502
898
|
|
@@ -505,6 +901,8 @@ declare namespace React {
|
|
505
901
|
* `React.ContextType` of your `static contextType`.
|
506
902
|
* Should be used with type annotation or static contextType.
|
507
903
|
*
|
904
|
+
* @example
|
905
|
+
*
|
508
906
|
* ```ts
|
509
907
|
* static contextType = MyContext
|
510
908
|
* // For TS pre-3.7:
|
@@ -513,14 +911,14 @@ declare namespace React {
|
|
513
911
|
* declare context: React.ContextType<typeof MyContext>
|
514
912
|
* ```
|
515
913
|
*
|
516
|
-
* @see https://react.dev/reference/react/Component#context
|
914
|
+
* @see {@link https://react.dev/reference/react/Component#context}
|
517
915
|
*/
|
518
916
|
context: unknown;
|
519
917
|
|
520
918
|
constructor(props: Readonly<P> | P);
|
521
919
|
/**
|
522
920
|
* @deprecated
|
523
|
-
* @see https://legacy.reactjs.org/docs/legacy-context.html
|
921
|
+
* @see {@link https://legacy.reactjs.org/docs/legacy-context.html}
|
524
922
|
*/
|
525
923
|
constructor(props: P, context: any);
|
526
924
|
|
@@ -548,6 +946,12 @@ declare namespace React {
|
|
548
946
|
|
549
947
|
class PureComponent<P = {}, S = {}, SS = any> extends Component<P, S, SS> {}
|
550
948
|
|
949
|
+
/**
|
950
|
+
* @deprecated Use `ClassicComponent` from `create-react-class`
|
951
|
+
*
|
952
|
+
* @see {@link https://legacy.reactjs.org/docs/react-without-es6.html Legacy React Docs}
|
953
|
+
* @see {@link https://www.npmjs.com/package/create-react-class `create-react-class` on npm}
|
954
|
+
*/
|
551
955
|
interface ClassicComponent<P = {}, S = {}> extends Component<P, S> {
|
552
956
|
replaceState(nextState: S, callback?: () => void): void;
|
553
957
|
isMounted(): boolean;
|
@@ -562,23 +966,140 @@ declare namespace React {
|
|
562
966
|
// Class Interfaces
|
563
967
|
// ----------------------------------------------------------------------
|
564
968
|
|
969
|
+
/**
|
970
|
+
* Represents the type of a function component. Can optionally
|
971
|
+
* receive a type argument that represents the props the component
|
972
|
+
* receives.
|
973
|
+
*
|
974
|
+
* @template P The props the component accepts.
|
975
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/function_components React TypeScript Cheatsheet}
|
976
|
+
* @alias for {@link FunctionComponent}
|
977
|
+
*
|
978
|
+
* @example
|
979
|
+
*
|
980
|
+
* ```tsx
|
981
|
+
* // With props:
|
982
|
+
* type Props = { name: string }
|
983
|
+
*
|
984
|
+
* const MyComponent: FC<Props> = (props) => {
|
985
|
+
* return <div>{props.name}</div>
|
986
|
+
* }
|
987
|
+
* ```
|
988
|
+
*
|
989
|
+
* @example
|
990
|
+
*
|
991
|
+
* ```tsx
|
992
|
+
* // Without props:
|
993
|
+
* const MyComponentWithoutProps: FC = () => {
|
994
|
+
* return <div>MyComponentWithoutProps</div>
|
995
|
+
* }
|
996
|
+
* ```
|
997
|
+
*/
|
565
998
|
type FC<P = {}> = FunctionComponent<P>;
|
566
999
|
|
1000
|
+
/**
|
1001
|
+
* Represents the type of a function component. Can optionally
|
1002
|
+
* receive a type argument that represents the props the component
|
1003
|
+
* accepts.
|
1004
|
+
*
|
1005
|
+
* @template P The props the component accepts.
|
1006
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/function_components React TypeScript Cheatsheet}
|
1007
|
+
*
|
1008
|
+
* @example
|
1009
|
+
*
|
1010
|
+
* ```tsx
|
1011
|
+
* // With props:
|
1012
|
+
* type Props = { name: string }
|
1013
|
+
*
|
1014
|
+
* const MyComponent: FunctionComponent<Props> = (props) => {
|
1015
|
+
* return <div>{props.name}</div>
|
1016
|
+
* }
|
1017
|
+
* ```
|
1018
|
+
*
|
1019
|
+
* @example
|
1020
|
+
*
|
1021
|
+
* ```tsx
|
1022
|
+
* // Without props:
|
1023
|
+
* const MyComponentWithoutProps: FunctionComponent = () => {
|
1024
|
+
* return <div>MyComponentWithoutProps</div>
|
1025
|
+
* }
|
1026
|
+
* ```
|
1027
|
+
*/
|
567
1028
|
interface FunctionComponent<P = {}> {
|
568
1029
|
(props: P, context?: any): ReactElement<any, any> | null;
|
1030
|
+
/**
|
1031
|
+
* Used to declare the types of the props accepted by the
|
1032
|
+
* component. These types will be checked during rendering
|
1033
|
+
* and in development only.
|
1034
|
+
*
|
1035
|
+
* We recommend using TypeScript instead of checking prop
|
1036
|
+
* types at runtime.
|
1037
|
+
*
|
1038
|
+
* @see {@link https://react.dev/reference/react/Component#static-proptypes React Docs}
|
1039
|
+
*/
|
569
1040
|
propTypes?: WeakValidationMap<P> | undefined;
|
1041
|
+
/**
|
1042
|
+
* @deprecated
|
1043
|
+
*
|
1044
|
+
* Lets you specify which legacy context is consumed by
|
1045
|
+
* this component.
|
1046
|
+
*
|
1047
|
+
* @see {@link https://legacy.reactjs.org/docs/legacy-context.html Legacy React Docs}
|
1048
|
+
*/
|
570
1049
|
contextTypes?: ValidationMap<any> | undefined;
|
1050
|
+
/**
|
1051
|
+
* Used to define default values for the props accepted by
|
1052
|
+
* the component.
|
1053
|
+
*
|
1054
|
+
* @see {@link https://react.dev/reference/react/Component#static-defaultprops React Docs}
|
1055
|
+
*
|
1056
|
+
* @example
|
1057
|
+
*
|
1058
|
+
* ```tsx
|
1059
|
+
* type Props = { name?: string }
|
1060
|
+
*
|
1061
|
+
* const MyComponent: FC<Props> = (props) => {
|
1062
|
+
* return <div>{props.name}</div>
|
1063
|
+
* }
|
1064
|
+
*
|
1065
|
+
* MyComponent.defaultProps = {
|
1066
|
+
* name: 'John Doe'
|
1067
|
+
* }
|
1068
|
+
* ```
|
1069
|
+
*/
|
571
1070
|
defaultProps?: Partial<P> | undefined;
|
1071
|
+
/**
|
1072
|
+
* Used in debugging messages. You might want to set it
|
1073
|
+
* explicitly if you want to display a different name for
|
1074
|
+
* debugging purposes.
|
1075
|
+
*
|
1076
|
+
* @see {@link https://legacy.reactjs.org/docs/react-component.html#displayname Legacy React Docs}
|
1077
|
+
*
|
1078
|
+
* @example
|
1079
|
+
*
|
1080
|
+
* ```tsx
|
1081
|
+
*
|
1082
|
+
* const MyComponent: FC = () => {
|
1083
|
+
* return <div>Hello!</div>
|
1084
|
+
* }
|
1085
|
+
*
|
1086
|
+
* MyComponent.displayName = 'MyAwesomeComponent'
|
1087
|
+
* ```
|
1088
|
+
*/
|
572
1089
|
displayName?: string | undefined;
|
573
1090
|
}
|
574
1091
|
|
575
1092
|
/**
|
576
|
-
* @deprecated - Equivalent
|
1093
|
+
* @deprecated - Equivalent to {@link React.FunctionComponent}.
|
1094
|
+
*
|
1095
|
+
* @see {@link React.FunctionComponent}
|
577
1096
|
*/
|
578
1097
|
type VFC<P = {}> = VoidFunctionComponent<P>;
|
579
1098
|
|
580
1099
|
/**
|
581
|
-
* @deprecated - Equivalent
|
1100
|
+
* @deprecated - Equivalent to {@link React.FunctionComponent}.
|
1101
|
+
*
|
1102
|
+
* @see {@link React.FunctionComponent}
|
582
1103
|
*/
|
583
1104
|
interface VoidFunctionComponent<P = {}> {
|
584
1105
|
(props: P, context?: any): ReactElement<any, any> | null;
|
@@ -588,42 +1109,126 @@ declare namespace React {
|
|
588
1109
|
displayName?: string | undefined;
|
589
1110
|
}
|
590
1111
|
|
1112
|
+
/**
|
1113
|
+
* The type of the ref received by a {@link ForwardRefRenderFunction}.
|
1114
|
+
*
|
1115
|
+
* @see {@link ForwardRefRenderFunction}
|
1116
|
+
*/
|
591
1117
|
type ForwardedRef<T> = ((instance: T | null) => void) | MutableRefObject<T | null> | null;
|
592
1118
|
|
1119
|
+
/**
|
1120
|
+
* The type of the function passed to {@link forwardRef}. This is considered different
|
1121
|
+
* to a normal {@link FunctionComponent} because it receives an additional argument,
|
1122
|
+
*
|
1123
|
+
* @param props Props passed to the component, if any.
|
1124
|
+
* @param ref A ref forwarded to the component of type {@link ForwardedRef}.
|
1125
|
+
*
|
1126
|
+
* @template T The type of the forwarded ref.
|
1127
|
+
* @template P The type of the props the component accepts.
|
1128
|
+
*
|
1129
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/forward_and_create_ref/ React TypeScript Cheatsheet}
|
1130
|
+
* @see {@link forwardRef}
|
1131
|
+
*/
|
593
1132
|
interface ForwardRefRenderFunction<T, P = {}> {
|
594
1133
|
(props: P, ref: ForwardedRef<T>): ReactElement | null;
|
1134
|
+
/**
|
1135
|
+
* Used in debugging messages. You might want to set it
|
1136
|
+
* explicitly if you want to display a different name for
|
1137
|
+
* debugging purposes.
|
1138
|
+
*
|
1139
|
+
* Will show `ForwardRef(${Component.displayName || Component.name})`
|
1140
|
+
* in devtools by default, but can be given its own specific name.
|
1141
|
+
*
|
1142
|
+
* @see {@link https://legacy.reactjs.org/docs/react-component.html#displayname Legacy React Docs}
|
1143
|
+
*/
|
595
1144
|
displayName?: string | undefined;
|
596
|
-
// explicit rejected with `never` required due to
|
597
|
-
// https://github.com/microsoft/TypeScript/issues/36826
|
598
1145
|
/**
|
599
|
-
* defaultProps are not supported on render functions
|
1146
|
+
* defaultProps are not supported on render functions passed to forwardRef.
|
1147
|
+
*
|
1148
|
+
* @see {@link https://github.com/microsoft/TypeScript/issues/36826 linked GitHub issue} for context
|
1149
|
+
* @see {@link https://react.dev/reference/react/Component#static-defaultprops React Docs}
|
600
1150
|
*/
|
601
1151
|
defaultProps?: never | undefined;
|
602
1152
|
/**
|
603
|
-
* propTypes are not supported on render functions
|
1153
|
+
* propTypes are not supported on render functions passed to forwardRef.
|
1154
|
+
*
|
1155
|
+
* @see {@link https://github.com/microsoft/TypeScript/issues/36826 linked GitHub issue} for context
|
1156
|
+
* @see {@link https://react.dev/reference/react/Component#static-proptypes React Docs}
|
604
1157
|
*/
|
605
1158
|
propTypes?: never | undefined;
|
606
1159
|
}
|
607
1160
|
|
1161
|
+
/**
|
1162
|
+
* Represents a component class in React.
|
1163
|
+
*
|
1164
|
+
* @template P The props the component accepts.
|
1165
|
+
* @template S The internal state of the component.
|
1166
|
+
*/
|
608
1167
|
interface ComponentClass<P = {}, S = ComponentState> extends StaticLifecycle<P, S> {
|
609
1168
|
new(props: P, context?: any): Component<P, S>;
|
1169
|
+
/**
|
1170
|
+
* Used to declare the types of the props accepted by the
|
1171
|
+
* component. These types will be checked during rendering
|
1172
|
+
* and in development only.
|
1173
|
+
*
|
1174
|
+
* We recommend using TypeScript instead of checking prop
|
1175
|
+
* types at runtime.
|
1176
|
+
*
|
1177
|
+
* @see {@link https://react.dev/reference/react/Component#static-proptypes React Docs}
|
1178
|
+
*/
|
610
1179
|
propTypes?: WeakValidationMap<P> | undefined;
|
611
1180
|
contextType?: Context<any> | undefined;
|
1181
|
+
/**
|
1182
|
+
* @deprecated use {@link ComponentClass.contextType} instead
|
1183
|
+
*
|
1184
|
+
* Lets you specify which legacy context is consumed by
|
1185
|
+
* this component.
|
1186
|
+
*
|
1187
|
+
* @see {@link https://legacy.reactjs.org/docs/legacy-context.html Legacy React Docs}
|
1188
|
+
*/
|
612
1189
|
contextTypes?: ValidationMap<any> | undefined;
|
1190
|
+
/**
|
1191
|
+
* @deprecated
|
1192
|
+
*
|
1193
|
+
* @see {@link https://legacy.reactjs.org/docs/legacy-context.html#how-to-use-context Legacy React Docs}
|
1194
|
+
*/
|
613
1195
|
childContextTypes?: ValidationMap<any> | undefined;
|
1196
|
+
/**
|
1197
|
+
* Used to define default values for the props accepted by
|
1198
|
+
* the component.
|
1199
|
+
*
|
1200
|
+
* @see {@link https://react.dev/reference/react/Component#static-defaultprops React Docs}
|
1201
|
+
*/
|
614
1202
|
defaultProps?: Partial<P> | undefined;
|
1203
|
+
/**
|
1204
|
+
* Used in debugging messages. You might want to set it
|
1205
|
+
* explicitly if you want to display a different name for
|
1206
|
+
* debugging purposes.
|
1207
|
+
*
|
1208
|
+
* @see {@link https://legacy.reactjs.org/docs/react-component.html#displayname Legacy React Docs}
|
1209
|
+
*/
|
615
1210
|
displayName?: string | undefined;
|
616
1211
|
}
|
617
1212
|
|
1213
|
+
/**
|
1214
|
+
* @deprecated Use `ClassicComponentClass` from `create-react-class`
|
1215
|
+
*
|
1216
|
+
* @see {@link https://legacy.reactjs.org/docs/react-without-es6.html Legacy React Docs}
|
1217
|
+
* @see {@link https://www.npmjs.com/package/create-react-class `create-react-class` on npm}
|
1218
|
+
*/
|
618
1219
|
interface ClassicComponentClass<P = {}> extends ComponentClass<P> {
|
619
1220
|
new(props: P, context?: any): ClassicComponent<P, ComponentState>;
|
620
1221
|
getDefaultProps?(): P;
|
621
1222
|
}
|
622
1223
|
|
623
1224
|
/**
|
624
|
-
*
|
1225
|
+
* Used in {@link createElement} and {@link createFactory} to represent
|
1226
|
+
* a class.
|
1227
|
+
*
|
1228
|
+
* An intersection type is used to infer multiple type parameters from
|
625
1229
|
* a single argument, which is useful for many top-level API defs.
|
626
|
-
* See https://github.com/Microsoft/TypeScript/issues/7234
|
1230
|
+
* See {@link https://github.com/Microsoft/TypeScript/issues/7234 this GitHub issue}
|
1231
|
+
* for more info.
|
627
1232
|
*/
|
628
1233
|
type ClassType<P, T extends Component<P, ComponentState>, C extends ComponentClass<P>> =
|
629
1234
|
& C
|
@@ -648,7 +1253,7 @@ declare namespace React {
|
|
648
1253
|
* `PureComponent` implements a shallow comparison on props and state and returns true if any
|
649
1254
|
* props or states have changed.
|
650
1255
|
*
|
651
|
-
* If false is returned,
|
1256
|
+
* If false is returned, {@link Component.render}, `componentWillUpdate`
|
652
1257
|
* and `componentDidUpdate` will not be called.
|
653
1258
|
*/
|
654
1259
|
shouldComponentUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): boolean;
|
@@ -690,47 +1295,49 @@ declare namespace React {
|
|
690
1295
|
// This should be "infer SS" but can't use it yet
|
691
1296
|
interface NewLifecycle<P, S, SS> {
|
692
1297
|
/**
|
693
|
-
* Runs before React applies the result of
|
694
|
-
* returns an object to be given to componentDidUpdate. Useful for saving
|
695
|
-
* things such as scroll position before
|
1298
|
+
* Runs before React applies the result of {@link Component.render render} to the document, and
|
1299
|
+
* returns an object to be given to {@link componentDidUpdate}. Useful for saving
|
1300
|
+
* things such as scroll position before {@link Component.render render} causes changes to it.
|
696
1301
|
*
|
697
|
-
* Note: the presence of
|
1302
|
+
* Note: the presence of this method prevents any of the deprecated
|
698
1303
|
* lifecycle events from running.
|
699
1304
|
*/
|
700
1305
|
getSnapshotBeforeUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>): SS | null;
|
701
1306
|
/**
|
702
1307
|
* Called immediately after updating occurs. Not called for the initial render.
|
703
1308
|
*
|
704
|
-
* The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.
|
1309
|
+
* The snapshot is only present if {@link getSnapshotBeforeUpdate} is present and returns non-null.
|
705
1310
|
*/
|
706
1311
|
componentDidUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>, snapshot?: SS): void;
|
707
1312
|
}
|
708
1313
|
|
709
1314
|
interface DeprecatedLifecycle<P, S> {
|
710
1315
|
/**
|
711
|
-
* Called immediately before mounting occurs, and before
|
1316
|
+
* Called immediately before mounting occurs, and before {@link Component.render}.
|
712
1317
|
* Avoid introducing any side-effects or subscriptions in this method.
|
713
1318
|
*
|
714
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
715
|
-
*
|
1319
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1320
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1321
|
+
* this from being invoked.
|
716
1322
|
*
|
717
1323
|
* @deprecated 16.3, use componentDidMount or the constructor instead; will stop working in React 17
|
718
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state
|
719
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
|
1324
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state}
|
1325
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path}
|
720
1326
|
*/
|
721
1327
|
componentWillMount?(): void;
|
722
1328
|
/**
|
723
|
-
* Called immediately before mounting occurs, and before
|
1329
|
+
* Called immediately before mounting occurs, and before {@link Component.render}.
|
724
1330
|
* Avoid introducing any side-effects or subscriptions in this method.
|
725
1331
|
*
|
726
1332
|
* This method will not stop working in React 17.
|
727
1333
|
*
|
728
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
729
|
-
*
|
1334
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1335
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1336
|
+
* this from being invoked.
|
730
1337
|
*
|
731
1338
|
* @deprecated 16.3, use componentDidMount or the constructor instead
|
732
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state
|
733
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
|
1339
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state}
|
1340
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path}
|
734
1341
|
*/
|
735
1342
|
UNSAFE_componentWillMount?(): void;
|
736
1343
|
/**
|
@@ -738,14 +1345,15 @@ declare namespace React {
|
|
738
1345
|
* React may call this even if props have not changed, so be sure to compare new and existing
|
739
1346
|
* props if you only want to handle changes.
|
740
1347
|
*
|
741
|
-
* Calling
|
1348
|
+
* Calling {@link Component.setState} generally does not trigger this method.
|
742
1349
|
*
|
743
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
744
|
-
*
|
1350
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1351
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1352
|
+
* this from being invoked.
|
745
1353
|
*
|
746
1354
|
* @deprecated 16.3, use static getDerivedStateFromProps instead; will stop working in React 17
|
747
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
|
748
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
|
1355
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props}
|
1356
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path}
|
749
1357
|
*/
|
750
1358
|
componentWillReceiveProps?(nextProps: Readonly<P>, nextContext: any): void;
|
751
1359
|
/**
|
@@ -753,44 +1361,47 @@ declare namespace React {
|
|
753
1361
|
* React may call this even if props have not changed, so be sure to compare new and existing
|
754
1362
|
* props if you only want to handle changes.
|
755
1363
|
*
|
756
|
-
* Calling
|
1364
|
+
* Calling {@link Component.setState} generally does not trigger this method.
|
757
1365
|
*
|
758
1366
|
* This method will not stop working in React 17.
|
759
1367
|
*
|
760
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
761
|
-
*
|
1368
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1369
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1370
|
+
* this from being invoked.
|
762
1371
|
*
|
763
1372
|
* @deprecated 16.3, use static getDerivedStateFromProps instead
|
764
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
|
765
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
|
1373
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props}
|
1374
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path}
|
766
1375
|
*/
|
767
1376
|
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<P>, nextContext: any): void;
|
768
1377
|
/**
|
769
1378
|
* Called immediately before rendering when new props or state is received. Not called for the initial render.
|
770
1379
|
*
|
771
|
-
* Note: You cannot call
|
1380
|
+
* Note: You cannot call {@link Component.setState} here.
|
772
1381
|
*
|
773
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
774
|
-
*
|
1382
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1383
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1384
|
+
* this from being invoked.
|
775
1385
|
*
|
776
1386
|
* @deprecated 16.3, use getSnapshotBeforeUpdate instead; will stop working in React 17
|
777
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update
|
778
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
|
1387
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update}
|
1388
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path}
|
779
1389
|
*/
|
780
1390
|
componentWillUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): void;
|
781
1391
|
/**
|
782
1392
|
* Called immediately before rendering when new props or state is received. Not called for the initial render.
|
783
1393
|
*
|
784
|
-
* Note: You cannot call
|
1394
|
+
* Note: You cannot call {@link Component.setState} here.
|
785
1395
|
*
|
786
1396
|
* This method will not stop working in React 17.
|
787
1397
|
*
|
788
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
789
|
-
*
|
1398
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1399
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1400
|
+
* this from being invoked.
|
790
1401
|
*
|
791
1402
|
* @deprecated 16.3, use getSnapshotBeforeUpdate instead
|
792
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update
|
793
|
-
* @see https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path
|
1403
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update}
|
1404
|
+
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path}
|
794
1405
|
*/
|
795
1406
|
UNSAFE_componentWillUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): void;
|
796
1407
|
}
|
@@ -814,7 +1425,9 @@ declare namespace React {
|
|
814
1425
|
}
|
815
1426
|
|
816
1427
|
/**
|
817
|
-
* @deprecated
|
1428
|
+
* @deprecated
|
1429
|
+
*
|
1430
|
+
* @see {@link https://legacy.reactjs.org/blog/2016/07/13/mixins-considered-harmful.html Mixins Considered Harmful}
|
818
1431
|
*/
|
819
1432
|
interface ComponentSpec<P, S> extends Mixin<P, S> {
|
820
1433
|
render(): ReactNode;
|
@@ -824,18 +1437,54 @@ declare namespace React {
|
|
824
1437
|
|
825
1438
|
function createRef<T>(): RefObject<T>;
|
826
1439
|
|
827
|
-
|
828
|
-
|
1440
|
+
/**
|
1441
|
+
* The type of the component returned from {@link forwardRef}.
|
1442
|
+
*
|
1443
|
+
* @template P The props the component accepts, if any.
|
1444
|
+
*
|
1445
|
+
* @see {@link ExoticComponent}
|
1446
|
+
*/
|
829
1447
|
interface ForwardRefExoticComponent<P> extends NamedExoticComponent<P> {
|
830
1448
|
defaultProps?: Partial<P> | undefined;
|
831
1449
|
propTypes?: WeakValidationMap<P> | undefined;
|
832
1450
|
}
|
833
1451
|
|
1452
|
+
/**
|
1453
|
+
* Lets your component expose a DOM node to a parent component
|
1454
|
+
* using a ref.
|
1455
|
+
*
|
1456
|
+
* @see {@link https://react.dev/reference/react/forwardRef React Docs}
|
1457
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/forward_and_create_ref/ React TypeScript Cheatsheet}
|
1458
|
+
*
|
1459
|
+
* @param render See the {@link ForwardRefRenderFunction}.
|
1460
|
+
*
|
1461
|
+
* @template T The type of the DOM node.
|
1462
|
+
* @template P The props the component accepts, if any.
|
1463
|
+
*
|
1464
|
+
* @example
|
1465
|
+
*
|
1466
|
+
* ```tsx
|
1467
|
+
* interface Props {
|
1468
|
+
* children?: ReactNode;
|
1469
|
+
* type: "submit" | "button";
|
1470
|
+
* }
|
1471
|
+
*
|
1472
|
+
* export const FancyButton = forwardRef<HTMLButtonElement, Props>((props, ref) => (
|
1473
|
+
* <button ref={ref} className="MyClassName" type={props.type}>
|
1474
|
+
* {props.children}
|
1475
|
+
* </button>
|
1476
|
+
* ));
|
1477
|
+
* ```
|
1478
|
+
*/
|
834
1479
|
function forwardRef<T, P = {}>(
|
835
1480
|
render: ForwardRefRenderFunction<T, P>,
|
836
1481
|
): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;
|
837
1482
|
|
838
|
-
/**
|
1483
|
+
/**
|
1484
|
+
* Omits the 'ref' attribute from the given props object.
|
1485
|
+
*
|
1486
|
+
* @template P The props object type.
|
1487
|
+
*/
|
839
1488
|
type PropsWithoutRef<P> =
|
840
1489
|
// Omit would not be sufficient for this. We'd like to avoid unnecessary mapping and need a distributive conditional to support unions.
|
841
1490
|
// see: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
|
@@ -854,28 +1503,107 @@ declare namespace React {
|
|
854
1503
|
type PropsWithChildren<P = unknown> = P & { children?: ReactNode | undefined };
|
855
1504
|
|
856
1505
|
/**
|
857
|
-
*
|
858
|
-
*
|
1506
|
+
* Used to retrieve the props a component accepts. Can either be passed a string,
|
1507
|
+
* indicating a DOM element (e.g. 'div', 'span', etc.) or the type of a React
|
1508
|
+
* component.
|
1509
|
+
*
|
1510
|
+
* It's usually better to use {@link ComponentPropsWithRef} or {@link ComponentPropsWithoutRef}
|
1511
|
+
* instead of this type, as they let you be explicit about whether or not to include
|
1512
|
+
* the `ref` prop.
|
1513
|
+
*
|
1514
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/react-types/componentprops/ React TypeScript Cheatsheet}
|
1515
|
+
*
|
1516
|
+
* @example
|
1517
|
+
*
|
1518
|
+
* ```tsx
|
1519
|
+
* // Retrieves the props an 'input' element accepts
|
1520
|
+
* type InputProps = React.ComponentProps<'input'>;
|
1521
|
+
* ```
|
1522
|
+
*
|
1523
|
+
* @example
|
1524
|
+
*
|
1525
|
+
* ```tsx
|
1526
|
+
* const MyComponent = (props: { foo: number, bar: string }) => <div />;
|
1527
|
+
*
|
1528
|
+
* // Retrieves the props 'MyComponent' accepts
|
1529
|
+
* type MyComponentProps = React.ComponentProps<typeof MyComponent>;
|
1530
|
+
* ```
|
859
1531
|
*/
|
860
1532
|
type ComponentProps<T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>> = T extends
|
861
1533
|
JSXElementConstructor<infer P> ? P
|
862
1534
|
: T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T]
|
863
1535
|
: {};
|
1536
|
+
|
864
1537
|
/**
|
865
|
-
*
|
1538
|
+
* Used to retrieve the props a component accepts with its ref. Can either be
|
1539
|
+
* passed a string, indicating a DOM element (e.g. 'div', 'span', etc.) or the
|
1540
|
+
* type of a React component.
|
1541
|
+
*
|
1542
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/react-types/componentprops/ React TypeScript Cheatsheet}
|
1543
|
+
*
|
1544
|
+
* @example
|
1545
|
+
*
|
1546
|
+
* ```tsx
|
1547
|
+
* // Retrieves the props an 'input' element accepts
|
1548
|
+
* type InputProps = React.ComponentPropsWithRef<'input'>;
|
1549
|
+
* ```
|
866
1550
|
*
|
867
|
-
*
|
1551
|
+
* @example
|
1552
|
+
*
|
1553
|
+
* ```tsx
|
1554
|
+
* const MyComponent = (props: { foo: number, bar: string }) => <div />;
|
1555
|
+
*
|
1556
|
+
* // Retrieves the props 'MyComponent' accepts
|
1557
|
+
* type MyComponentPropsWithRef = React.ComponentPropsWithRef<typeof MyComponent>;
|
1558
|
+
* ```
|
868
1559
|
*/
|
869
1560
|
type ComponentPropsWithRef<T extends ElementType> = T extends (new(props: infer P) => Component<any, any>)
|
870
1561
|
? PropsWithoutRef<P> & RefAttributes<InstanceType<T>>
|
871
1562
|
: PropsWithRef<ComponentProps<T>>;
|
872
1563
|
/**
|
873
|
-
*
|
1564
|
+
* Used to retrieve the props a custom component accepts with its ref.
|
1565
|
+
*
|
1566
|
+
* Unlike {@link ComponentPropsWithRef}, this only works with custom
|
1567
|
+
* components, i.e. components you define yourself. This is to improve
|
1568
|
+
* type-checking performance.
|
1569
|
+
*
|
1570
|
+
* @example
|
1571
|
+
*
|
1572
|
+
* ```tsx
|
1573
|
+
* const MyComponent = (props: { foo: number, bar: string }) => <div />;
|
1574
|
+
*
|
1575
|
+
* // Retrieves the props 'MyComponent' accepts
|
1576
|
+
* type MyComponentPropsWithRef = React.CustomComponentPropsWithRef<typeof MyComponent>;
|
1577
|
+
* ```
|
874
1578
|
*/
|
875
1579
|
type CustomComponentPropsWithRef<T extends ComponentType> = T extends (new(props: infer P) => Component<any, any>)
|
876
1580
|
? (PropsWithoutRef<P> & RefAttributes<InstanceType<T>>)
|
877
1581
|
: T extends ((props: infer P, legacyContext?: any) => ReactNode) ? PropsWithRef<P>
|
878
1582
|
: never;
|
1583
|
+
|
1584
|
+
/**
|
1585
|
+
* Used to retrieve the props a component accepts without its ref. Can either be
|
1586
|
+
* passed a string, indicating a DOM element (e.g. 'div', 'span', etc.) or the
|
1587
|
+
* type of a React component.
|
1588
|
+
*
|
1589
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/react-types/componentprops/ React TypeScript Cheatsheet}
|
1590
|
+
*
|
1591
|
+
* @example
|
1592
|
+
*
|
1593
|
+
* ```tsx
|
1594
|
+
* // Retrieves the props an 'input' element accepts
|
1595
|
+
* type InputProps = React.ComponentPropsWithoutRef<'input'>;
|
1596
|
+
* ```
|
1597
|
+
*
|
1598
|
+
* @example
|
1599
|
+
*
|
1600
|
+
* ```tsx
|
1601
|
+
* const MyComponent = (props: { foo: number, bar: string }) => <div />;
|
1602
|
+
*
|
1603
|
+
* // Retrieves the props 'MyComponent' accepts
|
1604
|
+
* type MyComponentPropsWithoutRef = React.ComponentPropsWithoutRef<typeof MyComponent>;
|
1605
|
+
* ```
|
1606
|
+
*/
|
879
1607
|
type ComponentPropsWithoutRef<T extends ElementType> = PropsWithoutRef<ComponentProps<T>>;
|
880
1608
|
|
881
1609
|
type ComponentRef<T extends ElementType> = T extends NamedExoticComponent<
|
@@ -946,14 +1674,14 @@ declare namespace React {
|
|
946
1674
|
* context value, as given by the nearest context provider for the given context.
|
947
1675
|
*
|
948
1676
|
* @version 16.8.0
|
949
|
-
* @see https://react.dev/reference/react/useContext
|
1677
|
+
* @see {@link https://react.dev/reference/react/useContext}
|
950
1678
|
*/
|
951
1679
|
function useContext<T>(context: Context<T> /*, (not public API) observedBits?: number|boolean */): T;
|
952
1680
|
/**
|
953
1681
|
* Returns a stateful value, and a function to update it.
|
954
1682
|
*
|
955
1683
|
* @version 16.8.0
|
956
|
-
* @see https://react.dev/reference/react/useState
|
1684
|
+
* @see {@link https://react.dev/reference/react/useState}
|
957
1685
|
*/
|
958
1686
|
function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
|
959
1687
|
// convenience overload when first argument is omitted
|
@@ -961,7 +1689,7 @@ declare namespace React {
|
|
961
1689
|
* Returns a stateful value, and a function to update it.
|
962
1690
|
*
|
963
1691
|
* @version 16.8.0
|
964
|
-
* @see https://react.dev/reference/react/useState
|
1692
|
+
* @see {@link https://react.dev/reference/react/useState}
|
965
1693
|
*/
|
966
1694
|
function useState<S = undefined>(): [S | undefined, Dispatch<SetStateAction<S | undefined>>];
|
967
1695
|
/**
|
@@ -972,7 +1700,7 @@ declare namespace React {
|
|
972
1700
|
* updates because you can pass `dispatch` down instead of callbacks.
|
973
1701
|
*
|
974
1702
|
* @version 16.8.0
|
975
|
-
* @see https://react.dev/reference/react/useReducer
|
1703
|
+
* @see {@link https://react.dev/reference/react/useReducer}
|
976
1704
|
*/
|
977
1705
|
// overload where dispatch could accept 0 arguments.
|
978
1706
|
function useReducer<R extends ReducerWithoutAction<any>, I>(
|
@@ -988,7 +1716,7 @@ declare namespace React {
|
|
988
1716
|
* updates because you can pass `dispatch` down instead of callbacks.
|
989
1717
|
*
|
990
1718
|
* @version 16.8.0
|
991
|
-
* @see https://react.dev/reference/react/useReducer
|
1719
|
+
* @see {@link https://react.dev/reference/react/useReducer}
|
992
1720
|
*/
|
993
1721
|
// overload where dispatch could accept 0 arguments.
|
994
1722
|
function useReducer<R extends ReducerWithoutAction<any>>(
|
@@ -1004,7 +1732,7 @@ declare namespace React {
|
|
1004
1732
|
* updates because you can pass `dispatch` down instead of callbacks.
|
1005
1733
|
*
|
1006
1734
|
* @version 16.8.0
|
1007
|
-
* @see https://react.dev/reference/react/useReducer
|
1735
|
+
* @see {@link https://react.dev/reference/react/useReducer}
|
1008
1736
|
*/
|
1009
1737
|
// overload where "I" may be a subset of ReducerState<R>; used to provide autocompletion.
|
1010
1738
|
// If "I" matches ReducerState<R> exactly then the last overload will allow initializer to be omitted.
|
@@ -1022,7 +1750,7 @@ declare namespace React {
|
|
1022
1750
|
* updates because you can pass `dispatch` down instead of callbacks.
|
1023
1751
|
*
|
1024
1752
|
* @version 16.8.0
|
1025
|
-
* @see https://react.dev/reference/react/useReducer
|
1753
|
+
* @see {@link https://react.dev/reference/react/useReducer}
|
1026
1754
|
*/
|
1027
1755
|
// overload for free "I"; all goes as long as initializer converts it into "ReducerState<R>".
|
1028
1756
|
function useReducer<R extends Reducer<any, any>, I>(
|
@@ -1038,7 +1766,7 @@ declare namespace React {
|
|
1038
1766
|
* updates because you can pass `dispatch` down instead of callbacks.
|
1039
1767
|
*
|
1040
1768
|
* @version 16.8.0
|
1041
|
-
* @see https://react.dev/reference/react/useReducer
|
1769
|
+
* @see {@link https://react.dev/reference/react/useReducer}
|
1042
1770
|
*/
|
1043
1771
|
|
1044
1772
|
// I'm not sure if I keep this 2-ary or if I make it (2,3)-ary; it's currently (2,3)-ary.
|
@@ -1063,7 +1791,7 @@ declare namespace React {
|
|
1063
1791
|
* value around similar to how you’d use instance fields in classes.
|
1064
1792
|
*
|
1065
1793
|
* @version 16.8.0
|
1066
|
-
* @see https://react.dev/reference/react/useRef
|
1794
|
+
* @see {@link https://react.dev/reference/react/useRef}
|
1067
1795
|
*/
|
1068
1796
|
function useRef<T>(initialValue: T): MutableRefObject<T>;
|
1069
1797
|
// convenience overload for refs given as a ref prop as they typically start with a null value
|
@@ -1078,7 +1806,7 @@ declare namespace React {
|
|
1078
1806
|
* of the generic argument.
|
1079
1807
|
*
|
1080
1808
|
* @version 16.8.0
|
1081
|
-
* @see https://react.dev/reference/react/useRef
|
1809
|
+
* @see {@link https://react.dev/reference/react/useRef}
|
1082
1810
|
*/
|
1083
1811
|
function useRef<T>(initialValue: T | null): RefObject<T>;
|
1084
1812
|
// convenience overload for potentially undefined initialValue / call with 0 arguments
|
@@ -1091,7 +1819,7 @@ declare namespace React {
|
|
1091
1819
|
* value around similar to how you’d use instance fields in classes.
|
1092
1820
|
*
|
1093
1821
|
* @version 16.8.0
|
1094
|
-
* @see https://react.dev/reference/react/useRef
|
1822
|
+
* @see {@link https://react.dev/reference/react/useRef}
|
1095
1823
|
*/
|
1096
1824
|
function useRef<T = undefined>(): MutableRefObject<T | undefined>;
|
1097
1825
|
/**
|
@@ -1105,7 +1833,7 @@ declare namespace React {
|
|
1105
1833
|
* `componentDidMount` and `componentDidUpdate`.
|
1106
1834
|
*
|
1107
1835
|
* @version 16.8.0
|
1108
|
-
* @see https://react.dev/reference/react/useLayoutEffect
|
1836
|
+
* @see {@link https://react.dev/reference/react/useLayoutEffect}
|
1109
1837
|
*/
|
1110
1838
|
function useLayoutEffect(effect: EffectCallback, deps?: DependencyList): void;
|
1111
1839
|
/**
|
@@ -1115,7 +1843,7 @@ declare namespace React {
|
|
1115
1843
|
* @param deps If present, effect will only activate if the values in the list change.
|
1116
1844
|
*
|
1117
1845
|
* @version 16.8.0
|
1118
|
-
* @see https://react.dev/reference/react/useEffect
|
1846
|
+
* @see {@link https://react.dev/reference/react/useEffect}
|
1119
1847
|
*/
|
1120
1848
|
function useEffect(effect: EffectCallback, deps?: DependencyList): void;
|
1121
1849
|
// NOTE: this does not accept strings, but this will have to be fixed by removing strings from type Ref<T>
|
@@ -1126,7 +1854,7 @@ declare namespace React {
|
|
1126
1854
|
* `useImperativeHandle` should be used with `React.forwardRef`.
|
1127
1855
|
*
|
1128
1856
|
* @version 16.8.0
|
1129
|
-
* @see https://react.dev/reference/react/useImperativeHandle
|
1857
|
+
* @see {@link https://react.dev/reference/react/useImperativeHandle}
|
1130
1858
|
*/
|
1131
1859
|
function useImperativeHandle<T, R extends T>(ref: Ref<T> | undefined, init: () => R, deps?: DependencyList): void;
|
1132
1860
|
// I made 'inputs' required here and in useMemo as there's no point to memoizing without the memoization key
|
@@ -1136,7 +1864,7 @@ declare namespace React {
|
|
1136
1864
|
* has changed.
|
1137
1865
|
*
|
1138
1866
|
* @version 16.8.0
|
1139
|
-
* @see https://react.dev/reference/react/useCallback
|
1867
|
+
* @see {@link https://react.dev/reference/react/useCallback}
|
1140
1868
|
*/
|
1141
1869
|
// A specific function type would not trigger implicit any.
|
1142
1870
|
// See https://github.com/DefinitelyTyped/DefinitelyTyped/issues/52873#issuecomment-845806435 for a comparison between `Function` and more specific types.
|
@@ -1146,7 +1874,7 @@ declare namespace React {
|
|
1146
1874
|
* `useMemo` will only recompute the memoized value when one of the `deps` has changed.
|
1147
1875
|
*
|
1148
1876
|
* @version 16.8.0
|
1149
|
-
* @see https://react.dev/reference/react/useMemo
|
1877
|
+
* @see {@link https://react.dev/reference/react/useMemo}
|
1150
1878
|
*/
|
1151
1879
|
// allow undefined, but don't make it optional as that is very likely a mistake
|
1152
1880
|
function useMemo<T>(factory: () => T, deps: DependencyList): T;
|
@@ -1157,7 +1885,7 @@ declare namespace React {
|
|
1157
1885
|
* It’s most valuable for custom hooks that are part of shared libraries.
|
1158
1886
|
*
|
1159
1887
|
* @version 16.8.0
|
1160
|
-
* @see https://react.dev/reference/react/useDebugValue
|
1888
|
+
* @see {@link https://react.dev/reference/react/useDebugValue}
|
1161
1889
|
*/
|
1162
1890
|
// the name of the custom hook is itself derived from the function name at runtime:
|
1163
1891
|
// it's just the function name without the "use" prefix.
|
@@ -1187,7 +1915,7 @@ declare namespace React {
|
|
1187
1915
|
*
|
1188
1916
|
* @param value The value that is going to be deferred
|
1189
1917
|
*
|
1190
|
-
* @see https://react.dev/reference/react/useDeferredValue
|
1918
|
+
* @see {@link https://react.dev/reference/react/useDeferredValue}
|
1191
1919
|
*/
|
1192
1920
|
export function useDeferredValue<T>(value: T): T;
|
1193
1921
|
|
@@ -1202,9 +1930,9 @@ declare namespace React {
|
|
1202
1930
|
* The first is a boolean, React’s way of informing us whether we’re waiting for the transition to finish.
|
1203
1931
|
* The second is a function that takes a callback. We can use it to tell React which state we want to defer.
|
1204
1932
|
*
|
1205
|
-
* **If some state update causes a component to suspend, that state update should be wrapped in a transition
|
1933
|
+
* **If some state update causes a component to suspend, that state update should be wrapped in a transition.**
|
1206
1934
|
*
|
1207
|
-
* @see https://react.dev/reference/react/useTransition
|
1935
|
+
* @see {@link https://react.dev/reference/react/useTransition}
|
1208
1936
|
*/
|
1209
1937
|
export function useTransition(): [boolean, TransitionStartFunction];
|
1210
1938
|
|
@@ -1221,7 +1949,7 @@ declare namespace React {
|
|
1221
1949
|
* @param effect Imperative function that can return a cleanup function
|
1222
1950
|
* @param deps If present, effect will only activate if the values in the list change.
|
1223
1951
|
*
|
1224
|
-
* @see https://github.com/facebook/react/pull/21913
|
1952
|
+
* @see {@link https://github.com/facebook/react/pull/21913}
|
1225
1953
|
*/
|
1226
1954
|
export function useInsertionEffect(effect: EffectCallback, deps?: DependencyList): void;
|
1227
1955
|
|
@@ -1229,7 +1957,7 @@ declare namespace React {
|
|
1229
1957
|
* @param subscribe
|
1230
1958
|
* @param getSnapshot
|
1231
1959
|
*
|
1232
|
-
* @see https://github.com/reactwg/react-18/discussions/86
|
1960
|
+
* @see {@link https://github.com/reactwg/react-18/discussions/86}
|
1233
1961
|
*/
|
1234
1962
|
// keep in sync with `useSyncExternalStore` from `use-sync-external-store`
|
1235
1963
|
export function useSyncExternalStore<Snapshot>(
|
@@ -2022,12 +2750,12 @@ declare namespace React {
|
|
2022
2750
|
// Living Standard
|
2023
2751
|
/**
|
2024
2752
|
* Hints at the type of data that might be entered by the user while editing the element or its contents
|
2025
|
-
* @see https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute
|
2753
|
+
* @see {@link https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute}
|
2026
2754
|
*/
|
2027
2755
|
inputMode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search" | undefined;
|
2028
2756
|
/**
|
2029
2757
|
* Specify that a standard HTML element should behave like a defined custom built-in element
|
2030
|
-
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#attr-is
|
2758
|
+
* @see {@link https://html.spec.whatwg.org/multipage/custom-elements.html#attr-is}
|
2031
2759
|
*/
|
2032
2760
|
is?: string | undefined;
|
2033
2761
|
}
|