@types/react 18.2.53 → 18.2.55
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 +229 -70
- react/package.json +2 -2
- react/ts5.0/index.d.ts +199 -45
react/README.md
CHANGED
@@ -8,7 +8,7 @@ This package contains type definitions for react (https://react.dev/).
|
|
8
8
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react.
|
9
9
|
|
10
10
|
### Additional Details
|
11
|
-
* Last updated:
|
11
|
+
* Last updated: Tue, 06 Feb 2024 09:35:42 GMT
|
12
12
|
* Dependencies: [@types/prop-types](https://npmjs.com/package/@types/prop-types), [@types/scheduler](https://npmjs.com/package/@types/scheduler), [csstype](https://npmjs.com/package/csstype)
|
13
13
|
|
14
14
|
# Credits
|
react/index.d.ts
CHANGED
@@ -91,8 +91,11 @@ declare namespace React {
|
|
91
91
|
| ComponentType<P>;
|
92
92
|
|
93
93
|
/**
|
94
|
-
* Represents any user-defined component, either as a function
|
95
|
-
*
|
94
|
+
* Represents any user-defined component, either as a function or a class.
|
95
|
+
*
|
96
|
+
* Similar to {@link JSXElementConstructor}, but with extra properties like
|
97
|
+
* {@link FunctionComponent.defaultProps defaultProps } and
|
98
|
+
* {@link ComponentClass.contextTypes contextTypes}.
|
96
99
|
*
|
97
100
|
* @template P The props the component accepts.
|
98
101
|
*
|
@@ -101,6 +104,15 @@ declare namespace React {
|
|
101
104
|
*/
|
102
105
|
type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
|
103
106
|
|
107
|
+
/**
|
108
|
+
* Represents any user-defined component, either as a function or a class.
|
109
|
+
*
|
110
|
+
* Similar to {@link ComponentType}, but without extra properties like
|
111
|
+
* {@link FunctionComponent.defaultProps defaultProps } and
|
112
|
+
* {@link ComponentClass.contextTypes contextTypes}.
|
113
|
+
*
|
114
|
+
* @template P The props the component accepts.
|
115
|
+
*/
|
104
116
|
type JSXElementConstructor<P> =
|
105
117
|
| ((
|
106
118
|
props: P,
|
@@ -137,6 +149,9 @@ declare namespace React {
|
|
137
149
|
* ```
|
138
150
|
*/
|
139
151
|
interface RefObject<T> {
|
152
|
+
/**
|
153
|
+
* The current value of the ref.
|
154
|
+
*/
|
140
155
|
readonly current: T | null;
|
141
156
|
}
|
142
157
|
|
@@ -175,22 +190,23 @@ declare namespace React {
|
|
175
190
|
* ```
|
176
191
|
*/
|
177
192
|
type LegacyRef<T> = string | Ref<T>;
|
193
|
+
|
178
194
|
/**
|
179
|
-
*
|
195
|
+
* Retrieves the type of the 'ref' prop for a given component type or tag name.
|
196
|
+
*
|
197
|
+
* @template C The component type.
|
180
198
|
*
|
181
|
-
*
|
182
|
-
* and used `React.ElementRef<typeof Foo>` then the type would be the instance of `Foo`.
|
183
|
-
* - React stateless functional components do not have a backing instance and so `React.ElementRef<typeof Bar>`
|
184
|
-
* (when `Bar` is `function Bar() {}`) will give you the `undefined` type.
|
185
|
-
* - JSX intrinsics like `div` will give you their DOM instance. For `React.ElementRef<'div'>` that would be
|
186
|
-
* `HTMLDivElement`. For `React.ElementRef<'input'>` that would be `HTMLInputElement`.
|
187
|
-
* - React stateless functional components that forward a `ref` will give you the `ElementRef` of the forwarded
|
188
|
-
* to component.
|
199
|
+
* @example
|
189
200
|
*
|
190
|
-
*
|
201
|
+
* ```tsx
|
202
|
+
* type MyComponentRef = React.ElementRef<typeof MyComponent>;
|
203
|
+
* ```
|
204
|
+
*
|
205
|
+
* @example
|
191
206
|
*
|
192
|
-
*
|
193
|
-
*
|
207
|
+
* ```tsx
|
208
|
+
* type DivRef = React.ElementRef<'div'>;
|
209
|
+
* ```
|
194
210
|
*/
|
195
211
|
type ElementRef<
|
196
212
|
C extends
|
@@ -216,30 +232,49 @@ declare namespace React {
|
|
216
232
|
*/
|
217
233
|
type Key = string | number | bigint;
|
218
234
|
|
219
|
-
/**
|
220
|
-
* @internal You shouldn't need to use this type since you never see these attributes
|
221
|
-
* inside your component or have to validate them.
|
222
|
-
*/
|
223
235
|
interface Attributes {
|
224
236
|
key?: Key | null | undefined;
|
225
237
|
}
|
226
238
|
interface RefAttributes<T> extends Attributes {
|
227
239
|
/**
|
228
240
|
* Allows getting a ref to the component instance.
|
229
|
-
* Once the component unmounts, React will set `ref.current` to `null`
|
230
|
-
*
|
241
|
+
* Once the component unmounts, React will set `ref.current` to `null`
|
242
|
+
* (or call the ref with `null` if you passed a callback ref).
|
243
|
+
*
|
244
|
+
* @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs}
|
231
245
|
*/
|
232
246
|
ref?: Ref<T> | undefined;
|
233
247
|
}
|
248
|
+
|
249
|
+
/**
|
250
|
+
* Represents the built-in attributes available to class components.
|
251
|
+
*/
|
234
252
|
interface ClassAttributes<T> extends Attributes {
|
235
253
|
/**
|
236
254
|
* Allows getting a ref to the component instance.
|
237
|
-
* Once the component unmounts, React will set `ref.current` to `null`
|
238
|
-
*
|
255
|
+
* Once the component unmounts, React will set `ref.current` to `null`
|
256
|
+
* (or call the ref with `null` if you passed a callback ref).
|
257
|
+
*
|
258
|
+
* @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs}
|
239
259
|
*/
|
240
260
|
ref?: LegacyRef<T> | undefined;
|
241
261
|
}
|
242
262
|
|
263
|
+
/**
|
264
|
+
* Represents a JSX element.
|
265
|
+
*
|
266
|
+
* Where {@link ReactNode} represents everything that can be rendered, `ReactElement`
|
267
|
+
* only represents JSX.
|
268
|
+
*
|
269
|
+
* @template P The type of the props object
|
270
|
+
* @template T The type of the component or tag
|
271
|
+
*
|
272
|
+
* @example
|
273
|
+
*
|
274
|
+
* ```tsx
|
275
|
+
* const element: ReactElement = <div />;
|
276
|
+
* ```
|
277
|
+
*/
|
243
278
|
interface ReactElement<
|
244
279
|
P = any,
|
245
280
|
T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>,
|
@@ -264,7 +299,7 @@ declare namespace React {
|
|
264
299
|
}
|
265
300
|
|
266
301
|
/**
|
267
|
-
* @deprecated Use
|
302
|
+
* @deprecated Use {@link ComponentElement} instead.
|
268
303
|
*/
|
269
304
|
type ClassicElement<P> = CElement<P, ClassicComponent<P, ComponentState>>;
|
270
305
|
|
@@ -352,11 +387,40 @@ declare namespace React {
|
|
352
387
|
type ReactFragment = Iterable<ReactNode>;
|
353
388
|
|
354
389
|
/**
|
355
|
-
* For internal usage only.
|
356
390
|
* Different release channels declare additional types of ReactNode this particular release channel accepts.
|
357
391
|
* App or library types should never augment this interface.
|
358
392
|
*/
|
359
393
|
interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_REACT_NODES {}
|
394
|
+
|
395
|
+
/**
|
396
|
+
* Represents all of the things React can render.
|
397
|
+
*
|
398
|
+
* Where {@link ReactElement} only represents JSX, `ReactNode` represents everything that can be rendered.
|
399
|
+
*
|
400
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/react-types/reactnode/ React TypeScript Cheatsheet}
|
401
|
+
*
|
402
|
+
* @example
|
403
|
+
*
|
404
|
+
* ```tsx
|
405
|
+
* // Typing children
|
406
|
+
* type Props = { children: ReactNode }
|
407
|
+
*
|
408
|
+
* const Component = ({ children }: Props) => <div>{children}</div>
|
409
|
+
*
|
410
|
+
* <Component>hello</Component>
|
411
|
+
* ```
|
412
|
+
*
|
413
|
+
* @example
|
414
|
+
*
|
415
|
+
* ```tsx
|
416
|
+
* // Typing a custom element
|
417
|
+
* type Props = { customElement: ReactNode }
|
418
|
+
*
|
419
|
+
* const Component = ({ customElement }: Props) => <div>{customElement}</div>
|
420
|
+
*
|
421
|
+
* <Component customElement={<div>hello</div>} />
|
422
|
+
* ```
|
423
|
+
*/
|
360
424
|
type ReactNode =
|
361
425
|
| ReactElement
|
362
426
|
| string
|
@@ -476,12 +540,21 @@ declare namespace React {
|
|
476
540
|
...children: ReactNode[]
|
477
541
|
): ReactElement<P>;
|
478
542
|
|
479
|
-
|
543
|
+
/**
|
544
|
+
* Describes the props accepted by a Context {@link Provider}.
|
545
|
+
*
|
546
|
+
* @template T The type of the value the context provides.
|
547
|
+
*/
|
480
548
|
interface ProviderProps<T> {
|
481
549
|
value: T;
|
482
550
|
children?: ReactNode | undefined;
|
483
551
|
}
|
484
552
|
|
553
|
+
/**
|
554
|
+
* Describes the props accepted by a Context {@link Consumer}.
|
555
|
+
*
|
556
|
+
* @template T The type of the value the context provides.
|
557
|
+
*/
|
485
558
|
interface ConsumerProps<T> {
|
486
559
|
children: (value: T) => ReactNode;
|
487
560
|
}
|
@@ -495,6 +568,8 @@ declare namespace React {
|
|
495
568
|
*
|
496
569
|
* But they are, in fact, not callable - instead, they are objects which
|
497
570
|
* are treated specially by the renderer.
|
571
|
+
*
|
572
|
+
* @template P The props the component accepts.
|
498
573
|
*/
|
499
574
|
interface ExoticComponent<P = {}> {
|
500
575
|
(props: P): ReactNode;
|
@@ -503,6 +578,8 @@ declare namespace React {
|
|
503
578
|
|
504
579
|
/**
|
505
580
|
* An {@link ExoticComponent} with a `displayName` property applied to it.
|
581
|
+
*
|
582
|
+
* @template P The props the component accepts.
|
506
583
|
*/
|
507
584
|
interface NamedExoticComponent<P = {}> extends ExoticComponent<P> {
|
508
585
|
/**
|
@@ -517,6 +594,8 @@ declare namespace React {
|
|
517
594
|
|
518
595
|
/**
|
519
596
|
* An {@link ExoticComponent} with a `propTypes` property applied to it.
|
597
|
+
*
|
598
|
+
* @template P The props the component accepts.
|
520
599
|
*/
|
521
600
|
interface ProviderExoticComponent<P> extends ExoticComponent<P> {
|
522
601
|
propTypes?: WeakValidationMap<P> | undefined;
|
@@ -525,6 +604,8 @@ declare namespace React {
|
|
525
604
|
/**
|
526
605
|
* Used to retrieve the type of a context object from a {@link Context}.
|
527
606
|
*
|
607
|
+
* @template C The context object.
|
608
|
+
*
|
528
609
|
* @example
|
529
610
|
*
|
530
611
|
* ```tsx
|
@@ -636,7 +717,9 @@ declare namespace React {
|
|
636
717
|
|
637
718
|
function isValidElement<P>(object: {} | null | undefined): object is ReactElement<P>;
|
638
719
|
|
639
|
-
|
720
|
+
/**
|
721
|
+
* Maintainer's note: Sync with {@link ReactChildren} until {@link ReactChildren} is removed.
|
722
|
+
*/
|
640
723
|
const Children: {
|
641
724
|
map<T, C>(
|
642
725
|
children: C | readonly C[],
|
@@ -815,11 +898,10 @@ declare namespace React {
|
|
815
898
|
// Base component for plain JS classes
|
816
899
|
interface Component<P = {}, S = {}, SS = any> extends ComponentLifecycle<P, S, SS> {}
|
817
900
|
class Component<P, S> {
|
818
|
-
// tslint won't let me format the sample code in a way that vscode likes it :(
|
819
901
|
/**
|
820
902
|
* If set, `this.context` will be set at runtime to the current value of the given Context.
|
821
903
|
*
|
822
|
-
*
|
904
|
+
* @example
|
823
905
|
*
|
824
906
|
* ```ts
|
825
907
|
* type MyContext = number
|
@@ -843,6 +925,7 @@ declare namespace React {
|
|
843
925
|
* `React.ContextType` of your `static contextType`.
|
844
926
|
* Should be used with type annotation or static contextType.
|
845
927
|
*
|
928
|
+
* @example
|
846
929
|
* ```ts
|
847
930
|
* static contextType = MyContext
|
848
931
|
* // For TS pre-3.7:
|
@@ -851,14 +934,14 @@ declare namespace React {
|
|
851
934
|
* declare context: React.ContextType<typeof MyContext>
|
852
935
|
* ```
|
853
936
|
*
|
854
|
-
* @see {@link https://react.dev/reference/react/Component#context}
|
937
|
+
* @see {@link https://react.dev/reference/react/Component#context React Docs}
|
855
938
|
*/
|
856
939
|
context: unknown;
|
857
940
|
|
858
941
|
constructor(props: Readonly<P> | P);
|
859
942
|
/**
|
860
943
|
* @deprecated
|
861
|
-
* @see {@link https://legacy.reactjs.org/docs/legacy-context.html}
|
944
|
+
* @see {@link https://legacy.reactjs.org/docs/legacy-context.html React Docs}
|
862
945
|
*/
|
863
946
|
constructor(props: P, context: any);
|
864
947
|
|
@@ -877,7 +960,8 @@ declare namespace React {
|
|
877
960
|
state: Readonly<S>;
|
878
961
|
/**
|
879
962
|
* @deprecated
|
880
|
-
*
|
963
|
+
*
|
964
|
+
* @see {@link https://legacy.reactjs.org/docs/refs-and-the-dom.html#legacy-api-string-refs Legacy React Docs}
|
881
965
|
*/
|
882
966
|
refs: {
|
883
967
|
[key: string]: ReactInstance;
|
@@ -1033,6 +1117,7 @@ declare namespace React {
|
|
1033
1117
|
* @deprecated - Equivalent to {@link React.FunctionComponent}.
|
1034
1118
|
*
|
1035
1119
|
* @see {@link React.FunctionComponent}
|
1120
|
+
* @alias {@link VoidFunctionComponent}
|
1036
1121
|
*/
|
1037
1122
|
type VFC<P = {}> = VoidFunctionComponent<P>;
|
1038
1123
|
|
@@ -1193,7 +1278,7 @@ declare namespace React {
|
|
1193
1278
|
* `PureComponent` implements a shallow comparison on props and state and returns true if any
|
1194
1279
|
* props or states have changed.
|
1195
1280
|
*
|
1196
|
-
* If false is returned,
|
1281
|
+
* If false is returned, {@link Component.render}, `componentWillUpdate`
|
1197
1282
|
* and `componentDidUpdate` will not be called.
|
1198
1283
|
*/
|
1199
1284
|
shouldComponentUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): boolean;
|
@@ -1235,45 +1320,47 @@ declare namespace React {
|
|
1235
1320
|
// This should be "infer SS" but can't use it yet
|
1236
1321
|
interface NewLifecycle<P, S, SS> {
|
1237
1322
|
/**
|
1238
|
-
* Runs before React applies the result of
|
1239
|
-
* returns an object to be given to componentDidUpdate. Useful for saving
|
1240
|
-
* things such as scroll position before
|
1323
|
+
* Runs before React applies the result of {@link Component.render render} to the document, and
|
1324
|
+
* returns an object to be given to {@link componentDidUpdate}. Useful for saving
|
1325
|
+
* things such as scroll position before {@link Component.render render} causes changes to it.
|
1241
1326
|
*
|
1242
|
-
* Note: the presence of
|
1327
|
+
* Note: the presence of this method prevents any of the deprecated
|
1243
1328
|
* lifecycle events from running.
|
1244
1329
|
*/
|
1245
1330
|
getSnapshotBeforeUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>): SS | null;
|
1246
1331
|
/**
|
1247
1332
|
* Called immediately after updating occurs. Not called for the initial render.
|
1248
1333
|
*
|
1249
|
-
* The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.
|
1334
|
+
* The snapshot is only present if {@link getSnapshotBeforeUpdate} is present and returns non-null.
|
1250
1335
|
*/
|
1251
1336
|
componentDidUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>, snapshot?: SS): void;
|
1252
1337
|
}
|
1253
1338
|
|
1254
1339
|
interface DeprecatedLifecycle<P, S> {
|
1255
1340
|
/**
|
1256
|
-
* Called immediately before mounting occurs, and before
|
1341
|
+
* Called immediately before mounting occurs, and before {@link Component.render}.
|
1257
1342
|
* Avoid introducing any side-effects or subscriptions in this method.
|
1258
1343
|
*
|
1259
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1260
|
-
*
|
1344
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1345
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1346
|
+
* this from being invoked.
|
1261
1347
|
*
|
1262
|
-
* @deprecated 16.3, use componentDidMount or the constructor instead; will stop working in React 17
|
1348
|
+
* @deprecated 16.3, use {@link ComponentLifecycle.componentDidMount componentDidMount} or the constructor instead; will stop working in React 17
|
1263
1349
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state}
|
1264
1350
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path}
|
1265
1351
|
*/
|
1266
1352
|
componentWillMount?(): void;
|
1267
1353
|
/**
|
1268
|
-
* Called immediately before mounting occurs, and before
|
1354
|
+
* Called immediately before mounting occurs, and before {@link Component.render}.
|
1269
1355
|
* Avoid introducing any side-effects or subscriptions in this method.
|
1270
1356
|
*
|
1271
1357
|
* This method will not stop working in React 17.
|
1272
1358
|
*
|
1273
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1274
|
-
*
|
1359
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1360
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1361
|
+
* this from being invoked.
|
1275
1362
|
*
|
1276
|
-
* @deprecated 16.3, use componentDidMount or the constructor instead
|
1363
|
+
* @deprecated 16.3, use {@link ComponentLifecycle.componentDidMount componentDidMount} or the constructor instead
|
1277
1364
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state}
|
1278
1365
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path}
|
1279
1366
|
*/
|
@@ -1283,12 +1370,13 @@ declare namespace React {
|
|
1283
1370
|
* React may call this even if props have not changed, so be sure to compare new and existing
|
1284
1371
|
* props if you only want to handle changes.
|
1285
1372
|
*
|
1286
|
-
* Calling
|
1373
|
+
* Calling {@link Component.setState} generally does not trigger this method.
|
1287
1374
|
*
|
1288
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1289
|
-
*
|
1375
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1376
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1377
|
+
* this from being invoked.
|
1290
1378
|
*
|
1291
|
-
* @deprecated 16.3, use static getDerivedStateFromProps instead; will stop working in React 17
|
1379
|
+
* @deprecated 16.3, use static {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} instead; will stop working in React 17
|
1292
1380
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props}
|
1293
1381
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path}
|
1294
1382
|
*/
|
@@ -1298,14 +1386,15 @@ declare namespace React {
|
|
1298
1386
|
* React may call this even if props have not changed, so be sure to compare new and existing
|
1299
1387
|
* props if you only want to handle changes.
|
1300
1388
|
*
|
1301
|
-
* Calling
|
1389
|
+
* Calling {@link Component.setState} generally does not trigger this method.
|
1302
1390
|
*
|
1303
1391
|
* This method will not stop working in React 17.
|
1304
1392
|
*
|
1305
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1306
|
-
*
|
1393
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1394
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1395
|
+
* this from being invoked.
|
1307
1396
|
*
|
1308
|
-
* @deprecated 16.3, use static getDerivedStateFromProps instead
|
1397
|
+
* @deprecated 16.3, use static {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} instead
|
1309
1398
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props}
|
1310
1399
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path}
|
1311
1400
|
*/
|
@@ -1313,10 +1402,11 @@ declare namespace React {
|
|
1313
1402
|
/**
|
1314
1403
|
* Called immediately before rendering when new props or state is received. Not called for the initial render.
|
1315
1404
|
*
|
1316
|
-
* Note: You cannot call
|
1405
|
+
* Note: You cannot call {@link Component.setState} here.
|
1317
1406
|
*
|
1318
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1319
|
-
*
|
1407
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1408
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1409
|
+
* this from being invoked.
|
1320
1410
|
*
|
1321
1411
|
* @deprecated 16.3, use getSnapshotBeforeUpdate instead; will stop working in React 17
|
1322
1412
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update}
|
@@ -1326,12 +1416,13 @@ declare namespace React {
|
|
1326
1416
|
/**
|
1327
1417
|
* Called immediately before rendering when new props or state is received. Not called for the initial render.
|
1328
1418
|
*
|
1329
|
-
* Note: You cannot call
|
1419
|
+
* Note: You cannot call {@link Component.setState} here.
|
1330
1420
|
*
|
1331
1421
|
* This method will not stop working in React 17.
|
1332
1422
|
*
|
1333
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1334
|
-
*
|
1423
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1424
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1425
|
+
* this from being invoked.
|
1335
1426
|
*
|
1336
1427
|
* @deprecated 16.3, use getSnapshotBeforeUpdate instead
|
1337
1428
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update}
|
@@ -1341,7 +1432,9 @@ declare namespace React {
|
|
1341
1432
|
}
|
1342
1433
|
|
1343
1434
|
/**
|
1344
|
-
* @deprecated
|
1435
|
+
* @deprecated
|
1436
|
+
*
|
1437
|
+
* @see {@link https://legacy.reactjs.org/blog/2016/07/13/mixins-considered-harmful.html Mixins Considered Harmful}
|
1345
1438
|
*/
|
1346
1439
|
interface Mixin<P, S> extends ComponentLifecycle<P, S> {
|
1347
1440
|
mixins?: Array<Mixin<P, S>> | undefined;
|
@@ -1414,7 +1507,11 @@ declare namespace React {
|
|
1414
1507
|
render: ForwardRefRenderFunction<T, P>,
|
1415
1508
|
): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;
|
1416
1509
|
|
1417
|
-
/**
|
1510
|
+
/**
|
1511
|
+
* Omits the 'ref' attribute from the given props object.
|
1512
|
+
*
|
1513
|
+
* @template P The props object type.
|
1514
|
+
*/
|
1418
1515
|
type PropsWithoutRef<P> =
|
1419
1516
|
// Omit would not be sufficient for this. We'd like to avoid unnecessary mapping and need a distributive conditional to support unions.
|
1420
1517
|
// see: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
|
@@ -1548,6 +1645,24 @@ declare namespace React {
|
|
1548
1645
|
readonly type: T;
|
1549
1646
|
};
|
1550
1647
|
|
1648
|
+
/**
|
1649
|
+
* Lets you skip re-rendering a component when its props are unchanged.
|
1650
|
+
*
|
1651
|
+
* @see {@link https://react.dev/reference/react/memo React Docs}
|
1652
|
+
*
|
1653
|
+
* @param Component The component to memoize.
|
1654
|
+
* @param propsAreEqual A function that will be used to determine if the props have changed.
|
1655
|
+
*
|
1656
|
+
* @example
|
1657
|
+
*
|
1658
|
+
* ```tsx
|
1659
|
+
* import { memo } from 'react';
|
1660
|
+
*
|
1661
|
+
* const SomeComponent = memo(function SomeComponent(props: { foo: string }) {
|
1662
|
+
* // ...
|
1663
|
+
* });
|
1664
|
+
* ```
|
1665
|
+
*/
|
1551
1666
|
function memo<P extends object>(
|
1552
1667
|
Component: FunctionComponent<P>,
|
1553
1668
|
propsAreEqual?: (prevProps: Readonly<P>, nextProps: Readonly<P>) => boolean,
|
@@ -1557,26 +1672,70 @@ declare namespace React {
|
|
1557
1672
|
propsAreEqual?: (prevProps: Readonly<ComponentProps<T>>, nextProps: Readonly<ComponentProps<T>>) => boolean,
|
1558
1673
|
): MemoExoticComponent<T>;
|
1559
1674
|
|
1560
|
-
|
1675
|
+
interface LazyExoticComponent<T extends ComponentType<any>>
|
1676
|
+
extends ExoticComponent<CustomComponentPropsWithRef<T>>
|
1677
|
+
{
|
1561
1678
|
readonly _result: T;
|
1562
|
-
}
|
1679
|
+
}
|
1563
1680
|
|
1681
|
+
/**
|
1682
|
+
* Lets you defer loading a component’s code until it is rendered for the first time.
|
1683
|
+
*
|
1684
|
+
* @see {@link https://react.dev/reference/react/lazy React Docs}
|
1685
|
+
*
|
1686
|
+
* @param load A function that returns a `Promise` or another thenable (a `Promise`-like object with a
|
1687
|
+
* then method). React will not call `load` until the first time you attempt to render the returned
|
1688
|
+
* component. After React first calls load, it will wait for it to resolve, and then render the
|
1689
|
+
* resolved value’s `.default` as a React component. Both the returned `Promise` and the `Promise`’s
|
1690
|
+
* resolved value will be cached, so React will not call load more than once. If the `Promise` rejects,
|
1691
|
+
* React will throw the rejection reason for the nearest Error Boundary to handle.
|
1692
|
+
*
|
1693
|
+
* @example
|
1694
|
+
*
|
1695
|
+
* ```tsx
|
1696
|
+
* import { lazy } from 'react';
|
1697
|
+
*
|
1698
|
+
* const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
|
1699
|
+
* ```
|
1700
|
+
*/
|
1564
1701
|
function lazy<T extends ComponentType<any>>(
|
1565
|
-
|
1702
|
+
load: () => Promise<{ default: T }>,
|
1566
1703
|
): LazyExoticComponent<T>;
|
1567
1704
|
|
1568
1705
|
//
|
1569
1706
|
// React Hooks
|
1570
1707
|
// ----------------------------------------------------------------------
|
1571
1708
|
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1709
|
+
/**
|
1710
|
+
* The instruction passed to a {@link Dispatch} function in {@link useState}
|
1711
|
+
* to tell React what the next value of the {@link useState} should be.
|
1712
|
+
*
|
1713
|
+
* Often found wrapped in {@link Dispatch}.
|
1714
|
+
*
|
1715
|
+
* @template S The type of the state.
|
1716
|
+
*
|
1717
|
+
* @example
|
1718
|
+
*
|
1719
|
+
* ```tsx
|
1720
|
+
* // This return type correctly represents the type of
|
1721
|
+
* // `setCount` in the example below.
|
1722
|
+
* const useCustomState = (): Dispatch<SetStateAction<number>> => {
|
1723
|
+
* const [count, setCount] = useState(0);
|
1724
|
+
*
|
1725
|
+
* return setCount;
|
1726
|
+
* }
|
1727
|
+
* ```
|
1728
|
+
*/
|
1575
1729
|
type SetStateAction<S> = S | ((prevState: S) => S);
|
1576
|
-
|
1577
|
-
|
1730
|
+
|
1731
|
+
/**
|
1732
|
+
* A function that can be used to update the state of a {@link useState}
|
1733
|
+
* or {@link useReducer} hook.
|
1734
|
+
*/
|
1578
1735
|
type Dispatch<A> = (value: A) => void;
|
1579
|
-
|
1736
|
+
/**
|
1737
|
+
* A {@link Dispatch} function can sometimes be called without any arguments.
|
1738
|
+
*/
|
1580
1739
|
type DispatchWithoutAction = () => void;
|
1581
1740
|
// Unlike redux, the actions _can_ be anything
|
1582
1741
|
type Reducer<S, A> = (prevState: S, action: A) => S;
|
react/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@types/react",
|
3
|
-
"version": "18.2.
|
3
|
+
"version": "18.2.55",
|
4
4
|
"description": "TypeScript definitions for react",
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react",
|
6
6
|
"license": "MIT",
|
@@ -201,6 +201,6 @@
|
|
201
201
|
"@types/scheduler": "*",
|
202
202
|
"csstype": "^3.0.2"
|
203
203
|
},
|
204
|
-
"typesPublisherContentHash": "
|
204
|
+
"typesPublisherContentHash": "41cc4f9203a010eff4158b37583d535e6867e99253ce9e203f10ddc95a2cdb36",
|
205
205
|
"typeScriptVersion": "4.6"
|
206
206
|
}
|
react/ts5.0/index.d.ts
CHANGED
@@ -101,6 +101,15 @@ declare namespace React {
|
|
101
101
|
*/
|
102
102
|
type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
|
103
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
|
+
*/
|
104
113
|
type JSXElementConstructor<P> =
|
105
114
|
| ((
|
106
115
|
props: P,
|
@@ -137,6 +146,9 @@ declare namespace React {
|
|
137
146
|
* ```
|
138
147
|
*/
|
139
148
|
interface RefObject<T> {
|
149
|
+
/**
|
150
|
+
* The current value of the ref.
|
151
|
+
*/
|
140
152
|
readonly current: T | null;
|
141
153
|
}
|
142
154
|
|
@@ -175,22 +187,23 @@ declare namespace React {
|
|
175
187
|
* ```
|
176
188
|
*/
|
177
189
|
type LegacyRef<T> = string | Ref<T>;
|
190
|
+
|
178
191
|
/**
|
179
|
-
*
|
192
|
+
* Retrieves the type of the 'ref' prop for a given component type or tag name.
|
193
|
+
*
|
194
|
+
* @template C The component type.
|
195
|
+
*
|
196
|
+
* @example
|
180
197
|
*
|
181
|
-
*
|
182
|
-
*
|
183
|
-
*
|
184
|
-
* (when `Bar` is `function Bar() {}`) will give you the `undefined` type.
|
185
|
-
* - JSX intrinsics like `div` will give you their DOM instance. For `React.ElementRef<'div'>` that would be
|
186
|
-
* `HTMLDivElement`. For `React.ElementRef<'input'>` that would be `HTMLInputElement`.
|
187
|
-
* - React stateless functional components that forward a `ref` will give you the `ElementRef` of the forwarded
|
188
|
-
* to component.
|
198
|
+
* ```tsx
|
199
|
+
* type MyComponentRef = React.ElementRef<typeof MyComponent>;
|
200
|
+
* ```
|
189
201
|
*
|
190
|
-
*
|
202
|
+
* @example
|
191
203
|
*
|
192
|
-
*
|
193
|
-
*
|
204
|
+
* ```tsx
|
205
|
+
* type DivRef = React.ElementRef<'div'>;
|
206
|
+
* ```
|
194
207
|
*/
|
195
208
|
type ElementRef<
|
196
209
|
C extends
|
@@ -231,6 +244,9 @@ declare namespace React {
|
|
231
244
|
*/
|
232
245
|
ref?: Ref<T> | undefined;
|
233
246
|
}
|
247
|
+
/**
|
248
|
+
* Represents the built-in attributes available to class components.
|
249
|
+
*/
|
234
250
|
interface ClassAttributes<T> extends Attributes {
|
235
251
|
/**
|
236
252
|
* Allows getting a ref to the component instance.
|
@@ -240,6 +256,21 @@ declare namespace React {
|
|
240
256
|
ref?: LegacyRef<T> | undefined;
|
241
257
|
}
|
242
258
|
|
259
|
+
/**
|
260
|
+
* Represents a JSX element.
|
261
|
+
*
|
262
|
+
* Where {@link ReactNode} represents everything that can be rendered, `ReactElement`
|
263
|
+
* only represents JSX.
|
264
|
+
*
|
265
|
+
* @template P The type of the props object
|
266
|
+
* @template T The type of the component or tag
|
267
|
+
*
|
268
|
+
* @example
|
269
|
+
*
|
270
|
+
* ```tsx
|
271
|
+
* const element: ReactElement = <div />;
|
272
|
+
* ```
|
273
|
+
*/
|
243
274
|
interface ReactElement<
|
244
275
|
P = any,
|
245
276
|
T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>,
|
@@ -358,6 +389,36 @@ declare namespace React {
|
|
358
389
|
* App or library types should never augment this interface.
|
359
390
|
*/
|
360
391
|
interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_REACT_NODES {}
|
392
|
+
|
393
|
+
/**
|
394
|
+
* Represents all of the things React can render.
|
395
|
+
*
|
396
|
+
* Where {@link ReactElement} only represents JSX, `ReactNode` represents everything that can be rendered.
|
397
|
+
*
|
398
|
+
* @see {@link https://react-typescript-cheatsheet.netlify.app/docs/react-types/reactnode/ React TypeScript Cheatsheet}
|
399
|
+
*
|
400
|
+
* @example
|
401
|
+
*
|
402
|
+
* ```tsx
|
403
|
+
* // Typing children
|
404
|
+
* type Props = { children: ReactNode }
|
405
|
+
*
|
406
|
+
* const Component = ({ children }: Props) => <div>{children}</div>
|
407
|
+
*
|
408
|
+
* <Component>hello</Component>
|
409
|
+
* ```
|
410
|
+
*
|
411
|
+
* @example
|
412
|
+
*
|
413
|
+
* ```tsx
|
414
|
+
* // Typing a custom element
|
415
|
+
* type Props = { customElement: ReactNode }
|
416
|
+
*
|
417
|
+
* const Component = ({ customElement }: Props) => <div>{customElement}</div>
|
418
|
+
*
|
419
|
+
* <Component customElement={<div>hello</div>} />
|
420
|
+
* ```
|
421
|
+
*/
|
361
422
|
type ReactNode =
|
362
423
|
| ReactElement
|
363
424
|
| string
|
@@ -477,12 +538,21 @@ declare namespace React {
|
|
477
538
|
...children: ReactNode[]
|
478
539
|
): ReactElement<P>;
|
479
540
|
|
480
|
-
|
541
|
+
/**
|
542
|
+
* Describes the props accepted by a Context {@link Provider}.
|
543
|
+
*
|
544
|
+
* @template T The type of the value the context provides.
|
545
|
+
*/
|
481
546
|
interface ProviderProps<T> {
|
482
547
|
value: T;
|
483
548
|
children?: ReactNode | undefined;
|
484
549
|
}
|
485
550
|
|
551
|
+
/**
|
552
|
+
* Describes the props accepted by a Context {@link Consumer}.
|
553
|
+
*
|
554
|
+
* @template T The type of the value the context provides.
|
555
|
+
*/
|
486
556
|
interface ConsumerProps<T> {
|
487
557
|
children: (value: T) => ReactNode;
|
488
558
|
}
|
@@ -496,6 +566,8 @@ declare namespace React {
|
|
496
566
|
*
|
497
567
|
* But they are, in fact, not callable - instead, they are objects which
|
498
568
|
* are treated specially by the renderer.
|
569
|
+
*
|
570
|
+
* @template P The props the component accepts.
|
499
571
|
*/
|
500
572
|
interface ExoticComponent<P = {}> {
|
501
573
|
(props: P): ReactElement | null;
|
@@ -504,6 +576,8 @@ declare namespace React {
|
|
504
576
|
|
505
577
|
/**
|
506
578
|
* An {@link ExoticComponent} with a `displayName` property applied to it.
|
579
|
+
*
|
580
|
+
* @template P The props the component accepts.
|
507
581
|
*/
|
508
582
|
interface NamedExoticComponent<P = {}> extends ExoticComponent<P> {
|
509
583
|
/**
|
@@ -518,6 +592,8 @@ declare namespace React {
|
|
518
592
|
|
519
593
|
/**
|
520
594
|
* An {@link ExoticComponent} with a `propTypes` property applied to it.
|
595
|
+
*
|
596
|
+
* @template P The props the component accepts.
|
521
597
|
*/
|
522
598
|
interface ProviderExoticComponent<P> extends ExoticComponent<P> {
|
523
599
|
propTypes?: WeakValidationMap<P> | undefined;
|
@@ -526,6 +602,8 @@ declare namespace React {
|
|
526
602
|
/**
|
527
603
|
* Used to retrieve the type of a context object from a {@link Context}.
|
528
604
|
*
|
605
|
+
* @template C The context object.
|
606
|
+
*
|
529
607
|
* @example
|
530
608
|
*
|
531
609
|
* ```tsx
|
@@ -639,7 +717,9 @@ declare namespace React {
|
|
639
717
|
|
640
718
|
function isValidElement<P>(object: {} | null | undefined): object is ReactElement<P>;
|
641
719
|
|
642
|
-
|
720
|
+
/**
|
721
|
+
* Maintainer's note: Sync with {@link ReactChildren} until {@link ReactChildren} is removed.
|
722
|
+
*/
|
643
723
|
const Children: {
|
644
724
|
map<T, C>(
|
645
725
|
children: C | readonly C[],
|
@@ -822,7 +902,7 @@ declare namespace React {
|
|
822
902
|
/**
|
823
903
|
* If set, `this.context` will be set at runtime to the current value of the given Context.
|
824
904
|
*
|
825
|
-
*
|
905
|
+
* @example
|
826
906
|
*
|
827
907
|
* ```ts
|
828
908
|
* type MyContext = number
|
@@ -846,6 +926,8 @@ declare namespace React {
|
|
846
926
|
* `React.ContextType` of your `static contextType`.
|
847
927
|
* Should be used with type annotation or static contextType.
|
848
928
|
*
|
929
|
+
* @example
|
930
|
+
*
|
849
931
|
* ```ts
|
850
932
|
* static contextType = MyContext
|
851
933
|
* // For TS pre-3.7:
|
@@ -1196,7 +1278,7 @@ declare namespace React {
|
|
1196
1278
|
* `PureComponent` implements a shallow comparison on props and state and returns true if any
|
1197
1279
|
* props or states have changed.
|
1198
1280
|
*
|
1199
|
-
* If false is returned,
|
1281
|
+
* If false is returned, {@link Component.render}, `componentWillUpdate`
|
1200
1282
|
* and `componentDidUpdate` will not be called.
|
1201
1283
|
*/
|
1202
1284
|
shouldComponentUpdate?(nextProps: Readonly<P>, nextState: Readonly<S>, nextContext: any): boolean;
|
@@ -1238,29 +1320,30 @@ declare namespace React {
|
|
1238
1320
|
// This should be "infer SS" but can't use it yet
|
1239
1321
|
interface NewLifecycle<P, S, SS> {
|
1240
1322
|
/**
|
1241
|
-
* Runs before React applies the result of
|
1242
|
-
* returns an object to be given to componentDidUpdate. Useful for saving
|
1243
|
-
* things such as scroll position before
|
1323
|
+
* Runs before React applies the result of {@link Component.render render} to the document, and
|
1324
|
+
* returns an object to be given to {@link componentDidUpdate}. Useful for saving
|
1325
|
+
* things such as scroll position before {@link Component.render render} causes changes to it.
|
1244
1326
|
*
|
1245
|
-
* Note: the presence of
|
1327
|
+
* Note: the presence of this method prevents any of the deprecated
|
1246
1328
|
* lifecycle events from running.
|
1247
1329
|
*/
|
1248
1330
|
getSnapshotBeforeUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>): SS | null;
|
1249
1331
|
/**
|
1250
1332
|
* Called immediately after updating occurs. Not called for the initial render.
|
1251
1333
|
*
|
1252
|
-
* The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.
|
1334
|
+
* The snapshot is only present if {@link getSnapshotBeforeUpdate} is present and returns non-null.
|
1253
1335
|
*/
|
1254
1336
|
componentDidUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>, snapshot?: SS): void;
|
1255
1337
|
}
|
1256
1338
|
|
1257
1339
|
interface DeprecatedLifecycle<P, S> {
|
1258
1340
|
/**
|
1259
|
-
* Called immediately before mounting occurs, and before
|
1341
|
+
* Called immediately before mounting occurs, and before {@link Component.render}.
|
1260
1342
|
* Avoid introducing any side-effects or subscriptions in this method.
|
1261
1343
|
*
|
1262
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1263
|
-
*
|
1344
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1345
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1346
|
+
* this from being invoked.
|
1264
1347
|
*
|
1265
1348
|
* @deprecated 16.3, use componentDidMount or the constructor instead; will stop working in React 17
|
1266
1349
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state}
|
@@ -1268,13 +1351,14 @@ declare namespace React {
|
|
1268
1351
|
*/
|
1269
1352
|
componentWillMount?(): void;
|
1270
1353
|
/**
|
1271
|
-
* Called immediately before mounting occurs, and before
|
1354
|
+
* Called immediately before mounting occurs, and before {@link Component.render}.
|
1272
1355
|
* Avoid introducing any side-effects or subscriptions in this method.
|
1273
1356
|
*
|
1274
1357
|
* This method will not stop working in React 17.
|
1275
1358
|
*
|
1276
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1277
|
-
*
|
1359
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1360
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1361
|
+
* this from being invoked.
|
1278
1362
|
*
|
1279
1363
|
* @deprecated 16.3, use componentDidMount or the constructor instead
|
1280
1364
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state}
|
@@ -1286,10 +1370,11 @@ declare namespace React {
|
|
1286
1370
|
* React may call this even if props have not changed, so be sure to compare new and existing
|
1287
1371
|
* props if you only want to handle changes.
|
1288
1372
|
*
|
1289
|
-
* Calling
|
1373
|
+
* Calling {@link Component.setState} generally does not trigger this method.
|
1290
1374
|
*
|
1291
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1292
|
-
*
|
1375
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1376
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1377
|
+
* this from being invoked.
|
1293
1378
|
*
|
1294
1379
|
* @deprecated 16.3, use static getDerivedStateFromProps instead; will stop working in React 17
|
1295
1380
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props}
|
@@ -1301,12 +1386,13 @@ declare namespace React {
|
|
1301
1386
|
* React may call this even if props have not changed, so be sure to compare new and existing
|
1302
1387
|
* props if you only want to handle changes.
|
1303
1388
|
*
|
1304
|
-
* Calling
|
1389
|
+
* Calling {@link Component.setState} generally does not trigger this method.
|
1305
1390
|
*
|
1306
1391
|
* This method will not stop working in React 17.
|
1307
1392
|
*
|
1308
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1309
|
-
*
|
1393
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1394
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1395
|
+
* this from being invoked.
|
1310
1396
|
*
|
1311
1397
|
* @deprecated 16.3, use static getDerivedStateFromProps instead
|
1312
1398
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props}
|
@@ -1316,10 +1402,11 @@ declare namespace React {
|
|
1316
1402
|
/**
|
1317
1403
|
* Called immediately before rendering when new props or state is received. Not called for the initial render.
|
1318
1404
|
*
|
1319
|
-
* Note: You cannot call
|
1405
|
+
* Note: You cannot call {@link Component.setState} here.
|
1320
1406
|
*
|
1321
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1322
|
-
*
|
1407
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1408
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1409
|
+
* this from being invoked.
|
1323
1410
|
*
|
1324
1411
|
* @deprecated 16.3, use getSnapshotBeforeUpdate instead; will stop working in React 17
|
1325
1412
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update}
|
@@ -1329,12 +1416,13 @@ declare namespace React {
|
|
1329
1416
|
/**
|
1330
1417
|
* Called immediately before rendering when new props or state is received. Not called for the initial render.
|
1331
1418
|
*
|
1332
|
-
* Note: You cannot call
|
1419
|
+
* Note: You cannot call {@link Component.setState} here.
|
1333
1420
|
*
|
1334
1421
|
* This method will not stop working in React 17.
|
1335
1422
|
*
|
1336
|
-
* Note: the presence of getSnapshotBeforeUpdate
|
1337
|
-
*
|
1423
|
+
* Note: the presence of {@link NewLifecycle.getSnapshotBeforeUpdate getSnapshotBeforeUpdate}
|
1424
|
+
* or {@link StaticLifecycle.getDerivedStateFromProps getDerivedStateFromProps} prevents
|
1425
|
+
* this from being invoked.
|
1338
1426
|
*
|
1339
1427
|
* @deprecated 16.3, use getSnapshotBeforeUpdate instead
|
1340
1428
|
* @see {@link https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update}
|
@@ -1417,7 +1505,11 @@ declare namespace React {
|
|
1417
1505
|
render: ForwardRefRenderFunction<T, P>,
|
1418
1506
|
): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;
|
1419
1507
|
|
1420
|
-
/**
|
1508
|
+
/**
|
1509
|
+
* Omits the 'ref' attribute from the given props object.
|
1510
|
+
*
|
1511
|
+
* @template P The props object type.
|
1512
|
+
*/
|
1421
1513
|
type PropsWithoutRef<P> =
|
1422
1514
|
// Omit would not be sufficient for this. We'd like to avoid unnecessary mapping and need a distributive conditional to support unions.
|
1423
1515
|
// see: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
|
@@ -1551,6 +1643,24 @@ declare namespace React {
|
|
1551
1643
|
readonly type: T;
|
1552
1644
|
};
|
1553
1645
|
|
1646
|
+
/**
|
1647
|
+
* Lets you skip re-rendering a component when its props are unchanged.
|
1648
|
+
*
|
1649
|
+
* @see {@link https://react.dev/reference/react/memo React Docs}
|
1650
|
+
*
|
1651
|
+
* @param Component The component to memoize.
|
1652
|
+
* @param propsAreEqual A function that will be used to determine if the props have changed.
|
1653
|
+
*
|
1654
|
+
* @example
|
1655
|
+
*
|
1656
|
+
* ```tsx
|
1657
|
+
* import { memo } from 'react';
|
1658
|
+
*
|
1659
|
+
* const SomeComponent = memo(function SomeComponent(props: { foo: string }) {
|
1660
|
+
* // ...
|
1661
|
+
* });
|
1662
|
+
* ```
|
1663
|
+
*/
|
1554
1664
|
function memo<P extends object>(
|
1555
1665
|
Component: FunctionComponent<P>,
|
1556
1666
|
propsAreEqual?: (prevProps: Readonly<P>, nextProps: Readonly<P>) => boolean,
|
@@ -1564,8 +1674,28 @@ declare namespace React {
|
|
1564
1674
|
readonly _result: T;
|
1565
1675
|
};
|
1566
1676
|
|
1677
|
+
/**
|
1678
|
+
* Lets you defer loading a component’s code until it is rendered for the first time.
|
1679
|
+
*
|
1680
|
+
* @see {@link https://react.dev/reference/react/lazy React Docs}
|
1681
|
+
*
|
1682
|
+
* @param load A function that returns a `Promise` or another thenable (a `Promise`-like object with a
|
1683
|
+
* then method). React will not call `load` until the first time you attempt to render the returned
|
1684
|
+
* component. After React first calls load, it will wait for it to resolve, and then render the
|
1685
|
+
* resolved value’s `.default` as a React component. Both the returned `Promise` and the `Promise`’s
|
1686
|
+
* resolved value will be cached, so React will not call load more than once. If the `Promise` rejects,
|
1687
|
+
* React will throw the rejection reason for the nearest Error Boundary to handle.
|
1688
|
+
*
|
1689
|
+
* @example
|
1690
|
+
*
|
1691
|
+
* ```tsx
|
1692
|
+
* import { lazy } from 'react';
|
1693
|
+
*
|
1694
|
+
* const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
|
1695
|
+
* ```
|
1696
|
+
*/
|
1567
1697
|
function lazy<T extends ComponentType<any>>(
|
1568
|
-
|
1698
|
+
load: () => Promise<{ default: T }>,
|
1569
1699
|
): LazyExoticComponent<T>;
|
1570
1700
|
|
1571
1701
|
//
|
@@ -1574,12 +1704,36 @@ declare namespace React {
|
|
1574
1704
|
|
1575
1705
|
// based on the code in https://github.com/facebook/react/pull/13968
|
1576
1706
|
|
1577
|
-
|
1707
|
+
/**
|
1708
|
+
* The instruction passed to a {@link Dispatch} function in {@link useState}
|
1709
|
+
* to tell React what the next value of the {@link useState} should be.
|
1710
|
+
*
|
1711
|
+
* Often found wrapped in {@link Dispatch}.
|
1712
|
+
*
|
1713
|
+
* @template S The type of the state.
|
1714
|
+
*
|
1715
|
+
* @example
|
1716
|
+
*
|
1717
|
+
* ```tsx
|
1718
|
+
* // This return type correctly represents the type of
|
1719
|
+
* // `setCount` in the example below.
|
1720
|
+
* const useCustomState = (): Dispatch<SetStateAction<number>> => {
|
1721
|
+
* const [count, setCount] = useState(0);
|
1722
|
+
*
|
1723
|
+
* return setCount;
|
1724
|
+
* }
|
1725
|
+
* ```
|
1726
|
+
*/
|
1578
1727
|
type SetStateAction<S> = S | ((prevState: S) => S);
|
1579
|
-
|
1580
|
-
|
1728
|
+
|
1729
|
+
/**
|
1730
|
+
* A function that can be used to update the state of a {@link useState}
|
1731
|
+
* or {@link useReducer} hook.
|
1732
|
+
*/
|
1581
1733
|
type Dispatch<A> = (value: A) => void;
|
1582
|
-
|
1734
|
+
/**
|
1735
|
+
* A {@link Dispatch} function can sometimes be called without any arguments.
|
1736
|
+
*/
|
1583
1737
|
type DispatchWithoutAction = () => void;
|
1584
1738
|
// Unlike redux, the actions _can_ be anything
|
1585
1739
|
type Reducer<S, A> = (prevState: S, action: A) => S;
|