-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
react.js
1047 lines (937 loc) · 33.3 KB
/
react.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
/**
* A UI node that can be rendered by React. React can render most primitives in
* addition to elements and arrays of nodes.
*/
declare type React$Node =
| void
| null
| boolean
| number
| string
| React$Element<any>
| React$Portal
| Iterable<?React$Node>;
/**
* Base class of ES6 React classes, modeled as a polymorphic class whose main
* type parameters are Props and State.
*/
declare class React$Component<Props, State = void> {
// fields
props: Props;
state: State;
// action methods
setState(
partialState: ?$ReadOnly<Partial<State>> | ((State, Props) => ?$ReadOnly<Partial<State>>),
callback?: () => mixed,
): void;
forceUpdate(callback?: () => void): void;
// lifecycle methods
constructor(props: Props, context?: any): void;
render(): React$Node;
componentWillMount(): mixed;
UNSAFE_componentWillMount(): mixed;
componentDidMount(): mixed;
componentWillReceiveProps(
nextProps: Props,
nextContext: any,
): mixed;
UNSAFE_componentWillReceiveProps(
nextProps: Props,
nextContext: any,
): mixed;
shouldComponentUpdate(
nextProps: Props,
nextState: State,
nextContext: any,
): boolean;
componentWillUpdate(
nextProps: Props,
nextState: State,
nextContext: any,
): mixed;
UNSAFE_componentWillUpdate(
nextProps: Props,
nextState: State,
nextContext: any,
): mixed;
componentDidUpdate(
prevProps: Props,
prevState: State,
prevContext: any,
): mixed;
componentWillUnmount(): mixed;
componentDidCatch(
error: Error,
info: { componentStack: string, ... }
): mixed;
// long tail of other stuff not modeled very well
refs: any;
context: any;
getChildContext(): any;
static displayName?: ?string;
static childContextTypes: empty;
static contextTypes: empty;
static propTypes: any;
// We don't add a type for `defaultProps` so that its type may be entirely
// inferred when we diff the type for `defaultProps` with `Props`. Otherwise
// the user would need to define a type (which would be redundant) to override
// the type we provide here in the base class.
//
// static defaultProps: $Shape<Props>;
}
declare class React$PureComponent<Props, State = void>
extends React$Component<Props, State> {
}
declare type React$AbstractComponentStatics = {
displayName?: ?string,
// This is only on function components, but trying to access name when
// displayName is undefined is a common pattern.
name?: ?string,
propTypes?: {[string] : any, ...},
...
};
/**
* The type of a component in React. A React component may be a:
*
* - Stateless functional components. Functions that take in props as an
* argument and return a React node.
* - ES6 class component. Components with state defined using the ES6 class syntax
*/
declare type React$ComponentType<-Config> = React$AbstractComponent<Config>;
/**
* The type of an element in React. A React element may be a:
*
* - String. These elements are intrinsics that depend on the React renderer
* implementation.
* - React component. See `ComponentType` for more information about its
* different variants.
*/
declare type React$ElementType =
| string
| React$ComponentType<empty>;
/**
* Type of a React element. React elements are commonly created using JSX
* literals, which desugar to React.createElement calls (see below).
*
* The internal structure of React.Element is intentionally omitted to
* discourage React.Element inspection.
*
* See https://react.dev/reference/react/Children#alternatives for alternatives.
*
* @deprecated You should not require very specific React elements.
* Use React.Node, React.MixedElement, or [render types](https://flow.org/en/docs/react/render-types/) instead.
*/
declare opaque type React$Element<+ElementType: React$ElementType, +P = React$ElementProps<ElementType>>: {...};
/**
* A type that should be used as the arguments of a render type.
* Referencing nominal components in type positions will produce this type.
*
* e.g.
* ```flow
* declare component Foo();
*
* type T1 = renders Foo;
* // Desugars to
* type T1 = renders React$RendersExactly<typeof Foo>;
* ```
*/
declare opaque type React$RendersExactly<+ElementType: React$ElementType>: React$Node;
/**
* Type of a React element. React elements are commonly created using JSX
* literals, which desugar to React.createElement calls (see below).
*
* The internal structure of React.Element is intentionally omitted to
* discourage React.Element inspection.
*
* See https://react.dev/reference/react/Children#alternatives for alternatives.
*
* @deprecated You should not require very specific React elements.
* Use React.Node, React.MixedElement, or [render types](https://flow.org/en/docs/react/render-types/) instead.
*/
declare type ExactReactElement_DEPRECATED<+C, +P = React$ElementProps<C>> = React$Element<C, P>;
declare type React$MixedElement = React$Element<React$ElementType>;
/**
* The type of the key that React uses to determine where items in a new list
* have moved.
*/
declare type React$Key = string | number;
declare opaque type React$RefObject<T>: {| current: T |}
/**
* The type of the `ref` prop on forwardRef components and the ref argument
* for useImperativeHandle.
*/
declare type React$RefSetter<-T> =
| { -current: T | null, ... }
| ((T | null) => mixed)
| null
| void;
/**
* The type of a React Context. React Contexts are created by calling
* createContext() with a default value.
*/
declare type React$Context<T> = {
Provider: React$ComponentType<{
+value: T,
+children?: React$Node,
...
}>,
Consumer: React$ComponentType<{ +children: (value: T) => ?React$Node, ... }>,
// Optional, user-specified value for custom display label in React DevTools.
displayName?: string,
...
}
/**
* A React portal node. The implementation of the portal node is hidden to React
* users so we use an opaque type.
*/
declare opaque type React$Portal;
declare type React$FragmentType = $Exports<'react'>['Fragment'];
declare namespace React {
type ComponentType<-P> = React$ComponentType<P>;
type PropsOf<E: string | React$MixedElement | React$RendersExactly<React$ElementType>> = E extends React$Element<infer C> ? React$ElementConfig<C> : E extends React$RendersExactly<infer C> ? React$ElementConfig<C> : (E extends string ? $JSXIntrinsics[E]['props'] : empty);
type PropOf<E: string | React$MixedElement | React$RendersExactly<React$ElementType>, K: string> = PropsOf<E>[K]
type RefOf<E: string | React$MixedElement | React$RendersExactly<React$ElementType>> = E extends React$Element<infer C> ? React$ElementRef<C> : E extends React$RendersExactly<infer C> ? React$ElementRef<C> : (E extends string ? $JSXIntrinsics[E]['instance'] : empty);
type MixedElement = React$MixedElement;
type ElementType = React$ElementType;
type Key = React$Key;
type RefSetter<-T> = React$RefSetter<T>;
type Node = React$Node;
type Context<T> = React$Context<T>;
type Portal = React$Portal;
type ElementProps<C> = React$ElementProps<C>;
type ElementConfig<C> = React$ElementConfig<C>;
type ElementRef<C> = React$ElementRef<C>;
type ChildrenArray<+T> = $ReadOnlyArray<ChildrenArray<T>> | T;
type ReactSetStateFunction<S> = ((S => S) | S) => void;
type RefObject<T> = React$RefObject<T>;
type Interaction = {
name: string,
timestamp: number,
...
};
}
/**
* Intentionally fully opaque to ban direct calls to `React.createElement`.
* Use JSX instead.
* @see https://react.dev/blog/2024/04/25/react-19-upgrade-guide#new-jsx-transform-is-now-required
*/
declare opaque type React$CreateElement;
type React$CloneElement =
& (<C: $Keys<$JSXIntrinsics>, E: React$Element<C>>(
element: E,
props?: ?Partial<$JSXIntrinsics[C]['props']>,
...children: $ReadOnlyArray<React$Node>
) => E)
& (<Props, C: React$ComponentType<empty>, E: React$Element<C, Props>>(
element: E,
props?: ?Partial<$ReadOnly<{|...$Exact<NoInfer<Props>>, key: React$Key, ref: React$RefSetter<React$ElementRef<NoInfer<C>>>|}>>,
) => E)
& (<Props, C: React$ComponentType<empty>, E: React$Element<C, Props>>(
element: E,
props: ?Partial<$ReadOnly<{|...$Exact<NoInfer<Props>>, key: React$Key, ref: React$RefSetter<React$ElementRef<NoInfer<C>>>|}>>,
children: NoInfer<Props>['children']
) => E)
& (<Props, C: React$ComponentType<empty>, E: React$Element<C, Props>>(
element: E,
props: ?Partial<$ReadOnly<{|...$Exact<NoInfer<Props>>, key: React$Key, ref: React$RefSetter<React$ElementRef<NoInfer<C>>>|}>>,
firstChild: NoInfer<Props>['children'][0],
secondChild: NoInfer<Props>['children'][1],
...restChildren: NoInfer<Props>['children'] extends [+first: mixed, +second: mixed, ...infer Rest] ? Rest : NoInfer<Props>['children']
) => E);
declare module react {
declare export const version: string;
/**
* `createContext` lets you create a context that components can provide or read.
*
* @see https://react.dev/reference/react/createContext
*/
declare export const createContext: typeof React.createContext;
/**
* `createElement` lets you create a React element.
* It serves as an alternative to writing JSX.
*
* @see https://react.dev/reference/react/createElement
*/
declare export const createElement: React$CreateElement;
/**
* Using cloneElement is uncommon and can lead to fragile code.
* [See common alternatives](https://react.dev/reference/react/cloneElement#alternatives)
*
* @see https://react.dev/reference/react/cloneElement
*/
declare export const cloneElement: React$CloneElement;
/**
* `createRef` creates a ref object which can contain arbitrary value.
*
* `createRef` is mostly used for class components.
* Function components typically rely on `useRef` instead.
*
* @see https://react.dev/reference/react/createRef
*/
declare export const createRef: typeof React.createRef;
/**
* `isValidElement` checks whether a value is a React element.
*
* It is very uncommon to need isValidElement.
* It’s mostly useful if you’re calling another API that only accepts
* elements (like cloneElement does) and you want to avoid an error
* when your argument is not a React element.
*
* Unless you have some very specific reason to add an isValidElement check,
* you probably don’t need it.
*
* @see https://react.dev/reference/react/isValidElement
*/
declare export function isValidElement(element: any): boolean;
/**
* `Component` lets you define a React component as a JavaScript class.
*
* We recommend defining components as functions instead of classes.
* [See how to migrate](https://react.dev/reference/react/PureComponent#alternatives).
*
* @see https://react.dev/reference/react/Component
*/
declare export const Component: typeof React$Component;
/**
* `PureComponent` is similar to `Component`, but it skip re-renders with same props.
*
* We recommend defining components as functions instead of classes.
* [See how to migrate](https://react.dev/reference/react/PureComponent#alternatives).
*
* @see https://react.dev/reference/react/PureComponent
*/
declare export const PureComponent: typeof React$PureComponent;
declare export type ComponentType<-P> = React$ComponentType<P>;
declare export type PropsOf<C: string | React$MixedElement | React$RendersExactly<React$ElementType>> = React.PropsOf<C>;
declare export type PropOf<C: string | React$MixedElement | React$RendersExactly<React$ElementType>, K: string> = React.PropOf<C, K>;
declare export type RefOf<C: string | React$MixedElement | React$RendersExactly<React$ElementType>> = React.RefOf<C>;
declare export type MixedElement = React$MixedElement;
declare export type ElementType = React$ElementType;
/**
* `<Fragment>`, often used via `<>...</>` syntax,
* lets you group elements without a wrapper node.
*
* @see https://react.dev/reference/react/Fragment
*/
declare export const Fragment: typeof React.Fragment;
declare export type Key = React$Key;
declare export type RefSetter<-T> = React$RefSetter<T>;
declare export type Node = React$Node;
declare export type Context<T> = React$Context<T>;
declare export type Portal = React$Portal;
/**
* `<StrictMode>` lets you find common bugs in your components early
* during development.
*
* @see https://react.dev/reference/react/StrictMode
*/
declare export const StrictMode: typeof React.StrictMode;
/**
* `<Suspense>` lets you display a fallback until its children have finished
* loading.
*
* @see https://react.dev/reference/react/Suspense
*/
declare export const Suspense: typeof React.Suspense; // 16.6+
declare export type ElementProps<C> = React$ElementProps<C>;
declare export type ElementConfig<C> = React$ElementConfig<C>;
declare export type ElementRef<C> = React$ElementRef<C>;
declare interface Thenable<T> {
then(
onFulfill: (value: T) => any,
onReject: (error: mixed) => mixed,
): mixed;
}
declare type Usable<T> = Thenable<T> | React$Context<T>;
declare export type ChildrenArray<+T> = React.ChildrenArray<T>;
/**
* `Children`lets you manipulate and transform the JSX received as the
* children prop.
*
* Using `Children` is uncommon and can lead to fragile code.
* [See common alternatives](https://react.dev/reference/react/Children#alternatives).
*
* @see https://react.dev/reference/react/Children
*/
declare export const Children: typeof React.Children;
/**
* `forwardRef` lets your component expose a DOM node to parent component
* with a ref.
*
* @see https://react.dev/reference/react/forwardRef
*/
declare export const forwardRef: typeof React.forwardRef;
/**
* `memo` lets you skip re-rendering a component when its props are unchanged.
*
* @see https://react.dev/reference/react/memo
*/
declare export const memo: typeof React.memo;
/**
* `lazy` lets you defer loading component’s code until it is rendered for
* the first time.
*
* @see https://react.dev/reference/react/lazy
*/
declare export const lazy: typeof React.lazy;
declare type MaybeCleanUpFn = void | (() => void);
declare export type ReactSetStateFunction<S> = React.ReactSetStateFunction<S>;
/**
* `use` is a React Hook that lets you read the value of a resource like a
* `Promise` or `context`.
*
* @see https://react.dev/reference/react/use
*/
declare export function use<T>(usable: Usable<T>): T;
/**
* `useContext` is a React Hook that lets you read and subscribe to context
* from your component.
*
* @see https://react.dev/reference/react/useContext
*/
declare export const useContext: typeof React.useContext;
/**
* `useState` is a React Hook that lets you add a
* [state variable](https://react.dev/learn/state-a-components-memory)
* to your component.
*
* @see https://react.dev/reference/react/useState
*/
declare export const useState: typeof React.useState;
declare type Dispatch<A> = (A) => void;
/**
* `useReducer` is a React Hook that lets you add a
* [reducer](https://react.dev/learn/extracting-state-logic-into-a-reducer)
* to your component.
*
* @see https://react.dev/reference/react/useReducer
*/
declare export const useReducer: typeof React.useReducer;
declare export type RefObject<T> = React$RefObject<T>;
/**
* `useRef` is a React Hook that lets you reference a value that's
* not needed for rendering.
*
* @see https://react.dev/reference/react/useRef
*/
declare export const useRef: typeof React.useRef;
/**
* `useDebugValue` is a React Hook that lets you add a label to a custom Hook
* in React DevTools.
*
* @see https://react.dev/reference/react/useDebugValue
*/
declare export function useDebugValue(value: any): void;
/**
* `useEffect` is a React Hook that lets you
* [synchronize a component with an external system](https://react.dev/learn/synchronizing-with-effects).
*
* @see https://react.dev/reference/react/useEffect
*/
declare export const useEffect: typeof React.useEffect;
/**
* `useLayoutEffect` is a version of useEffect that fires before the browser
* repaints the screen.
*
* `useLayoutEffect` can hurt performance. Prefer `useEffect` when possible.
*
* @see https://react.dev/reference/react/useLayoutEffect
*/
declare export const useLayoutEffect: typeof React.useLayoutEffect;
/**
* `useCallback` is a React Hook that lets you cache a function definition
* between re-renders.
*
* @see https://react.dev/reference/react/useCallback
*/
declare export const useCallback: typeof React.useCallback;
/**
* useMemo is a React Hook that lets you cache the result of a calculation
* between re-renders.
*
* @see https://react.dev/reference/react/useMemo
*/
declare export const useMemo: typeof React.useMemo;
/**
* `useImperativeHandle` is a React Hook that lets you customize the handle
* exposed as a ref.
*
* @see https://react.dev/reference/react/useImperativeHandle
*/
declare export const useImperativeHandle: typeof React.useImperativeHandle;
/**
* `useDeferredValue` is a React Hook that lets you defer updating
* a part of the UI.
*
* @see https://react.dev/reference/react/useDeferredValue
*/
declare export const useDeferredValue: typeof React.useDeferredValue;
/**
* `useTransition` is a React Hook that lets you update the state
* without blocking the UI.
*
* @see https://react.dev/reference/react/useTransition
*/
declare export const useTransition: typeof React.useTransition;
/**
* `startTransition` lets you update the state without blocking the UI.
*
* @see https://react.dev/reference/react/startTransition
*/
declare export const startTransition: typeof React.startTransition;
/**
* `useId` is a React Hook for generating unique IDs that
* can be passed to accessibility attributes.
*
* @see https://react.dev/reference/react/useId
*/
declare export const useId: typeof React.useId;
/**
* `useInsertionEffect` allows inserting elements into the DOM
* before any layout effects fire.
*
* `useInsertionEffect` is for CSS-in-JS library authors. Unless you are
* working on a CSS-in-JS library and need a place to inject the styles,
* you probably want `useEffect` or `useLayoutEffect` instead.
*
* @see https://react.dev/reference/react/useInsertionEffect
*/
declare export const useInsertionEffect: typeof React.useInsertionEffect;
/**
* `useSyncExternalStore` is a React Hook that lets you subscribe
* to an external store.
*
* @see https://react.dev/reference/react/useSyncExternalStore
*/
declare export const useSyncExternalStore: typeof React.useSyncExternalStore;
/**
* `useOptimistic` is a React Hook that lets you optimistically update
* the UI.
*
* @see https://react.dev/reference/react/useOptimistic
*/
declare export const useOptimistic: typeof React.useOptimistic;
/**
* `useActionState` is a Hook that allows you to update state based on the
* result of a form action.
*
* @see https://react.dev/reference/react/useActionState
*/
declare export const useActionState: typeof React.useActionState;
declare export type Interaction = React.Interaction;
declare type ProfilerOnRenderFnType = (
id: string,
phase: "mount" | "update",
actualDuration: number,
baseDuration: number,
startTime: number,
commitTime: number,
interactions: Set<Interaction>,
) => void;
/**
* `<Profiler>` lets you measure rendering performance of a
* React tree programmatically.
*
* @see https://react.dev/reference/react/Profiler
*/
declare export const Profiler: typeof React.Profiler;
declare type TimeoutConfig = {|
timeoutMs: number,
|};
declare namespace React {
declare const version: string;
/**
* `memo` lets you skip re-rendering a component when its props are unchanged.
*
* @see https://react.dev/reference/react/memo
*/
declare function memo<
Config: {...},
Instance = mixed,
Renders: React$Node = React$Node,
>(
component: component(
ref: React.RefSetter<Instance>,
...Config
) renders Renders,
equal?: (Config, Config) => boolean,
): component(ref: React.RefSetter<Instance>, ...Config) renders Renders;
/**
* `lazy` lets you defer loading component’s code until it is rendered for
* the first time.
*
* @see https://react.dev/reference/react/lazy
*/
declare function lazy<
Config: {...},
Instance = mixed,
Renders: React$Node = React$Node,
>(
component: () => Promise<
$ReadOnly<{
default: component(
ref: React.RefSetter<Instance>,
...Config
) renders Renders,
...
}>,
>,
): component(ref: React.RefSetter<Instance>, ...Config) renders Renders;
/**
* `createContext` lets you create a context that components can provide or read.
*
* @see https://react.dev/reference/react/createContext
*/
declare function createContext<T>(
defaultValue: T,
calculateChangedBits: ?(a: T, b: T) => number,
): React$Context<T>;
/**
* `createElement` lets you create a React element.
* It serves as an alternative to writing JSX.
*
* @see https://react.dev/reference/react/createElement
*/
declare const createElement: React$CreateElement;
/**
* Using cloneElement is uncommon and can lead to fragile code.
* [See common alternatives](https://react.dev/reference/react/cloneElement#alternatives)
*
* @see https://react.dev/reference/react/cloneElement
*/
declare const cloneElement: React$CloneElement;
/**
* `createRef` creates a ref object which can contain arbitrary value.
*
* `createRef` is mostly used for class components.
* Function components typically rely on `useRef` instead.
*
* @see https://react.dev/reference/react/createRef
*/
declare function createRef<T>(
): React$RefObject<T | null>;
/**
* `isValidElement` checks whether a value is a React element.
*
* It is very uncommon to need isValidElement.
* It’s mostly useful if you’re calling another API that only accepts
* elements (like cloneElement does) and you want to avoid an error
* when your argument is not a React element.
*
* Unless you have some very specific reason to add an isValidElement check,
* you probably don’t need it.
*
* @see https://react.dev/reference/react/isValidElement
*/
declare function isValidElement(element: any): boolean;
/**
* `Component` lets you define a React component as a JavaScript class.
*
* We recommend defining components as functions instead of classes.
* [See how to migrate](https://react.dev/reference/react/PureComponent#alternatives).
*
* @see https://react.dev/reference/react/Component
*/
declare const Component: typeof React$Component;
/**
* `PureComponent` is similar to `Component`, but it skip re-renders with same props.
*
* We recommend defining components as functions instead of classes.
* [See how to migrate](https://react.dev/reference/react/PureComponent#alternatives).
*
* @see https://react.dev/reference/react/PureComponent
*/
declare const PureComponent: typeof React$PureComponent;
declare function forwardRef<
Config: {...},
Instance,
Renders: React$Node = React$Node,
>(
render: (props: Config, ref: React$RefSetter<Instance>) => Renders,
): component(ref: React.RefSetter<Instance>, ...Config) renders Renders;
/**
* `<Fragment>`, often used via `<>...</>` syntax,
* lets you group elements without a wrapper node.
*
* @see https://react.dev/reference/react/Fragment
*/
declare component Fragment<Renders: React$Node = void>(
children?: Renders,
) renders Renders;
/**
* `Children`lets you manipulate and transform the JSX received as the
* children prop.
*
* Using `Children` is uncommon and can lead to fragile code.
* [See common alternatives](https://react.dev/reference/react/Children#alternatives).
*
* @see https://react.dev/reference/react/Children
*/
declare const Children: {
map<T, U, This>(
children: ChildrenArray<T>,
fn: (this : This, child: $NonMaybeType<T>, index: number) => U,
thisArg: This,
): Array<$NonMaybeType<U>>,
forEach<T, This>(
children: ChildrenArray<T>,
fn: (this : This, child: T, index: number) => mixed,
thisArg: This,
): void,
count(children: ChildrenArray<any>): number,
only<T>(children: ChildrenArray<T>): $NonMaybeType<T>,
toArray<T>(children: ChildrenArray<T>): Array<$NonMaybeType<T>>,
...
};
/**
* `<StrictMode>` lets you find common bugs in your components early
* during development.
*
* @see https://react.dev/reference/react/StrictMode
*/
declare const StrictMode: ({ +children?: React$Node, ... }) => React$Node;
/**
* `<Suspense>` lets you display a fallback until its children have finished
* loading.
*
* @see https://react.dev/reference/react/Suspense
*/
declare const Suspense: React$ComponentType<{
+children?: React$Node,
+fallback?: React$Node,
...
}>; // 16.6+
/**
* `<Profiler>` lets you measure rendering performance of a
* React tree programmatically.
*
* @see https://react.dev/reference/react/Profiler
*/
declare const Profiler: component(
children?: React$Node,
id: string,
onRender: ProfilerOnRenderFnType,
);
/**
* `useContext` is a React Hook that lets you read and subscribe to context
* from your component.
*
* @see https://react.dev/reference/react/useContext
*/
declare hook useContext<T>(context: React$Context<T>): T;
/**
* `useState` is a React Hook that lets you add a
* [state variable](https://react.dev/learn/state-a-components-memory)
* to your component.
*
* @see https://react.dev/reference/react/useState
*/
declare hook useState<S>(
initialState: (() => S) | S,
): [S, ReactSetStateFunction<S>];
/**
* `useReducer` is a React Hook that lets you add a
* [reducer](https://react.dev/learn/extracting-state-logic-into-a-reducer)
* to your component.
*
* @see https://react.dev/reference/react/useReducer
*/
declare hook useReducer<S, A>(
reducer: (S, A) => S,
initialState: S,
): [S, Dispatch<A>];
declare hook useReducer<S, A>(
reducer: (S, A) => S,
initialState: S,
init: void,
): [S, Dispatch<A>];
declare hook useReducer<S, A, I>(
reducer: (S, A) => S,
initialArg: I,
init: (I) => S,
): [S, Dispatch<A>];
/**
* `useRef` is a React Hook that lets you reference a value that's
* not needed for rendering.
*
* @see https://react.dev/reference/react/useRef
*/
declare hook useRef<T>(initialValue: T): RefObject<T>;
/**
* `useEffect` is a React Hook that lets you
* [synchronize a component with an external system](https://react.dev/learn/synchronizing-with-effects).
*
* @see https://react.dev/reference/react/useEffect
*/
declare hook useEffect(
create: () => MaybeCleanUpFn,
inputs?: ?$ReadOnlyArray<mixed>,
): void;
/**
* `useLayoutEffect` is a version of useEffect that fires before the browser
* repaints the screen.
*
* `useLayoutEffect` can hurt performance. Prefer `useEffect` when possible.
*
* @see https://react.dev/reference/react/useLayoutEffect
*/
declare hook useLayoutEffect(
create: () => MaybeCleanUpFn,
inputs?: ?$ReadOnlyArray<mixed>,
): void;
/**
* `useCallback` is a React Hook that lets you cache a function definition
* between re-renders.
*
* @see https://react.dev/reference/react/useCallback
*/
declare hook useCallback<T: (...args: $ReadOnlyArray<empty>) => mixed>(
callback: T,
inputs: ?$ReadOnlyArray<mixed>,
): T;
/**
* useMemo is a React Hook that lets you cache the result of a calculation
* between re-renders.
*
* @see https://react.dev/reference/react/useMemo
*/
declare hook useMemo<T>(
create: () => T,
inputs: ?$ReadOnlyArray<mixed>,
): T;
/**
* `useImperativeHandle` is a React Hook that lets you customize the handle
* exposed as a ref.
*
* @see https://react.dev/reference/react/useImperativeHandle
*/
declare hook useImperativeHandle<T>(
ref: React$RefSetter<T> | null | void,
create: () => T,
inputs: ?$ReadOnlyArray<mixed>,
): void;
/**
* `useDeferredValue` is a React Hook that lets you defer updating
* a part of the UI.
*
* @see https://react.dev/reference/react/useDeferredValue
*/
declare hook useDeferredValue<T>(value: T): T;
/**
* `useTransition` is a React Hook that lets you update the state
* without blocking the UI.
*
* @see https://react.dev/reference/react/useTransition
*/
declare hook useTransition(): [boolean, (() => void) => void];
/**
* `startTransition` lets you update the state without blocking the UI.
*
* @see https://react.dev/reference/react/startTransition
*/
declare function startTransition(() => void): void;
/**
* `useId` is a React Hook for generating unique IDs that
* can be passed to accessibility attributes.
*
* @see https://react.dev/reference/react/useId
*/
declare hook useId(): string;
/**
* `useInsertionEffect` allows inserting elements into the DOM
* before any layout effects fire.
*
* `useInsertionEffect` is for CSS-in-JS library authors. Unless you are
* working on a CSS-in-JS library and need a place to inject the styles,
* you probably want `useEffect` or `useLayoutEffect` instead.
*
* @see https://react.dev/reference/react/useInsertionEffect
*/
declare hook useInsertionEffect(
create: () => MaybeCleanUpFn,
inputs?: ?$ReadOnlyArray<mixed>,
): void;
/**
* `useSyncExternalStore` is a React Hook that lets you subscribe
* to an external store.
*
* @see https://react.dev/reference/react/useSyncExternalStore
*/
declare hook useSyncExternalStore<Snapshot>(
subscribe: (onStoreChange: () => void) => () => void,
getSnapshot: () => Snapshot,
getServerSnapshot?: () => Snapshot,
): Snapshot;
/**
* `useOptimistic` is a React Hook that lets you optimistically update
* the UI.
*
* @see https://react.dev/reference/react/useOptimistic
*/
declare hook useOptimistic<State>(
passthrough: State,
): [State, (action: State | ((pendingState: State) => State)) => void];
declare hook useOptimistic<State, Action>(
passthrough: State,
reducer: (state: State, action: Action) => State,
): [State, (action: Action) => void];
/**
* `useActionState` is a Hook that allows you to update state based on the
* result of a form action.
*
* @see https://react.dev/reference/react/useActionState
*/
declare hook useActionState<State>(
action: (state: Promise<State>) => State | Promise<State>,
initialState: Promise<State>,
permalink?: string,