forked from rescript-lang/rescript-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReact.res
473 lines (378 loc) · 17.7 KB
/
React.res
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
type element = Jsx.element
@val external null: element = "null"
external float: float => element = "%identity"
external int: int => element = "%identity"
external string: string => element = "%identity"
external array: array<element> => element = "%identity"
type componentLike<'props, 'return> = Jsx.componentLike<'props, 'return>
type component<'props> = Jsx.component<'props>
external component: componentLike<'props, element> => component<'props> = "%identity"
@module("react")
external createElement: (component<'props>, 'props) => element = "createElement"
@module("react")
external cloneElement: (element, 'props) => element = "cloneElement"
@module("react")
external isValidElement: 'a => bool = "isValidElement"
@variadic @module("react")
external createElementVariadic: (component<'props>, 'props, array<element>) => element =
"createElement"
@module("react/jsx-runtime")
external jsx: (component<'props>, 'props) => element = "jsx"
@module("react/jsx-runtime")
external jsxKeyed: (component<'props>, 'props, ~key: string=?, @ignore unit) => element = "jsx"
@module("react/jsx-runtime")
external jsxs: (component<'props>, 'props) => element = "jsxs"
@module("react/jsx-runtime")
external jsxsKeyed: (component<'props>, 'props, ~key: string=?, @ignore unit) => element = "jsxs"
type fragmentProps = {children?: element}
@module("react/jsx-runtime") external jsxFragment: component<fragmentProps> = "Fragment"
type ref<'value> = {mutable current: 'value}
module Ref = {
@deprecated("Please use the type React.ref instead")
type t<'value> = ref<'value>
@deprecated("Please directly read from ref.current instead") @get
external current: ref<'value> => 'value = "current"
@deprecated("Please directly assign to ref.current instead") @set
external setCurrent: (ref<'value>, 'value) => unit = "current"
}
@module("react")
external createRef: unit => ref<Js.nullable<'a>> = "createRef"
module Children = {
@module("react") @scope("Children")
external map: (element, element => element) => element = "map"
@module("react") @scope("Children")
external mapWithIndex: (element, @uncurry (element, int) => element) => element = "map"
@module("react") @scope("Children")
external forEach: (element, element => unit) => unit = "forEach"
@module("react") @scope("Children")
external forEachWithIndex: (element, @uncurry (element, int) => unit) => unit = "forEach"
@module("react") @scope("Children")
external count: element => int = "count"
@module("react") @scope("Children")
external only: element => element = "only"
@module("react") @scope("Children")
external toArray: element => array<element> = "toArray"
}
module Context = {
type t<'context>
type props<'context> = {
value: 'context,
children: element,
}
@get
external provider: t<'context> => component<props<'context>> = "Provider"
}
@module("react")
external createContext: 'a => Context.t<'a> = "createContext"
@module("react")
external forwardRef: (@uncurry ('props, Js.Nullable.t<ref<'a>>) => element) => component<'props> =
"forwardRef"
@module("react")
external memo: component<'props> => component<'props> = "memo"
@module("react")
external memoCustomCompareProps: (
component<'props>,
@uncurry ('props, 'props) => bool,
) => component<'props> = "memo"
@module("react") external fragment: component<fragmentProps> = "Fragment"
module Fragment = {
type props = {key?: string, children: element}
@module("react")
external make: component<props> = "Fragment"
}
module StrictMode = {
type props = {key?: string, children: element}
@module("react")
external make: component<props> = "StrictMode"
}
module Suspense = {
type props = {key?: string, children?: element, fallback?: element}
@module("react")
external make: component<props> = "Suspense"
}
type dynamicallyImportedModule<'a> = {default: component<'a>}
@module("react")
external lazy_: (unit => promise<dynamicallyImportedModule<'a>>) => component<'a> = "lazy"
let lazy_ = load => lazy_(async () => {default: await load()})
/* HOOKS */
/*
* Yeah, we know this api isn't great. tl;dr: useReducer instead.
* It's because useState can take functions or non-function values and treats
* them differently. Lazy initializer + callback which returns state is the
* only way to safely have any type of state and be able to update it correctly.
*/
@module("react")
external useState: (@uncurry (unit => 'state)) => ('state, ('state => 'state) => unit) = "useState"
@module("react")
external useReducer: (@uncurry ('state, 'action) => 'state, 'state) => ('state, 'action => unit) =
"useReducer"
@module("react")
external useReducerWithMapState: (
@uncurry ('state, 'action) => 'state,
'initialState,
@uncurry ('initialState => 'state),
) => ('state, 'action => unit) = "useReducer"
@module("react")
external useEffectOnEveryRender: (@uncurry (unit => option<unit => unit>)) => unit = "useEffect"
@module("react")
external useEffect: (@uncurry (unit => option<unit => unit>), 'deps) => unit = "useEffect"
@module("react") @deprecated("Please use useEffect or useEffectOnEveryRender instead")
external useEffect0: (@uncurry (unit => option<unit => unit>), @as(json`[]`) _) => unit =
"useEffect"
@module("react") @deprecated("Please use useEffect or useEffectOnEveryRender instead")
external useEffect1: (@uncurry (unit => option<unit => unit>), array<'a>) => unit = "useEffect"
@module("react") @deprecated("Please use useEffect or useEffectOnEveryRender instead")
external useEffect2: (@uncurry (unit => option<unit => unit>), ('a, 'b)) => unit = "useEffect"
@module("react") @deprecated("Please use useEffect or useEffectOnEveryRender instead")
external useEffect3: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c)) => unit = "useEffect"
@module("react") @deprecated("Please use useEffect or useEffectOnEveryRender instead")
external useEffect4: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd)) => unit =
"useEffect"
@module("react") @deprecated("Please use useEffect or useEffectOnEveryRender instead")
external useEffect5: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd, 'e)) => unit =
"useEffect"
@module("react") @deprecated("Please use useEffect or useEffectOnEveryRender instead")
external useEffect6: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd, 'e, 'f)) => unit =
"useEffect"
@module("react") @deprecated("Please use useEffect or useEffectOnEveryRender instead")
external useEffect7: (
@uncurry (unit => option<unit => unit>),
('a, 'b, 'c, 'd, 'e, 'f, 'g),
) => unit = "useEffect"
@module("react")
external useLayoutEffectOnEveryRender: (@uncurry (unit => option<unit => unit>)) => unit =
"useLayoutEffect"
@module("react")
external useLayoutEffect: (@uncurry (unit => option<unit => unit>), 'deps) => unit =
"useLayoutEffect"
@module("react") @deprecated("Please use useLayoutEffect or useLayoutEffectOnEveryRender instead")
external useLayoutEffect0: (@uncurry (unit => option<unit => unit>), @as(json`[]`) _) => unit =
"useLayoutEffect"
@module("react") @deprecated("Please use useLayoutEffect or useLayoutEffectOnEveryRender instead")
external useLayoutEffect1: (@uncurry (unit => option<unit => unit>), array<'a>) => unit =
"useLayoutEffect"
@module("react") @deprecated("Please use useLayoutEffect or useLayoutEffectOnEveryRender instead")
external useLayoutEffect2: (@uncurry (unit => option<unit => unit>), ('a, 'b)) => unit =
"useLayoutEffect"
@module("react") @deprecated("Please use useLayoutEffect or useLayoutEffectOnEveryRender instead")
external useLayoutEffect3: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c)) => unit =
"useLayoutEffect"
@module("react") @deprecated("Please use useLayoutEffect or useLayoutEffectOnEveryRender instead")
external useLayoutEffect4: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd)) => unit =
"useLayoutEffect"
@module("react") @deprecated("Please use useLayoutEffect or useLayoutEffectOnEveryRender instead")
external useLayoutEffect5: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd, 'e)) => unit =
"useLayoutEffect"
@module("react") @deprecated("Please use useLayoutEffect or useLayoutEffectOnEveryRender instead")
external useLayoutEffect6: (
@uncurry (unit => option<unit => unit>),
('a, 'b, 'c, 'd, 'e, 'f),
) => unit = "useLayoutEffect"
@module("react") @deprecated("Please use useLayoutEffect or useLayoutEffectOnEveryRender instead")
external useLayoutEffect7: (
@uncurry (unit => option<unit => unit>),
('a, 'b, 'c, 'd, 'e, 'f, 'g),
) => unit = "useLayoutEffect"
@module("react")
external useMemo: (@uncurry (unit => 'any), 'deps) => 'any = "useMemo"
@module("react") @deprecated("Please use useMemo instead")
external useMemo0: (@uncurry (unit => 'any), @as(json`[]`) _) => 'any = "useMemo"
@module("react") @deprecated("Please use useMemo instead")
external useMemo1: (@uncurry (unit => 'any), array<'a>) => 'any = "useMemo"
@module("react") @deprecated("Please use useMemo instead")
external useMemo2: (@uncurry (unit => 'any), ('a, 'b)) => 'any = "useMemo"
@module("react") @deprecated("Please use useMemo instead")
external useMemo3: (@uncurry (unit => 'any), ('a, 'b, 'c)) => 'any = "useMemo"
@module("react") @deprecated("Please use useMemo instead")
external useMemo4: (@uncurry (unit => 'any), ('a, 'b, 'c, 'd)) => 'any = "useMemo"
@module("react") @deprecated("Please use useMemo instead")
external useMemo5: (@uncurry (unit => 'any), ('a, 'b, 'c, 'd, 'e)) => 'any = "useMemo"
@module("react") @deprecated("Please use useMemo instead")
external useMemo6: (@uncurry (unit => 'any), ('a, 'b, 'c, 'd, 'e, 'f)) => 'any = "useMemo"
@module("react") @deprecated("Please use useMemo instead")
external useMemo7: (@uncurry (unit => 'any), ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => 'any = "useMemo"
@module("react")
external useCallback: ('f, 'deps) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback0: ('f, @as(json`[]`) _) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback1: ('f, array<'a>) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback2: ('f, ('a, 'b)) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback3: ('f, ('a, 'b, 'c)) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback4: ('f, ('a, 'b, 'c, 'd)) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback5: ('f, ('a, 'b, 'c, 'd, 'e)) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback6: ('callback, ('a, 'b, 'c, 'd, 'e, 'f)) => 'callback = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback7: ('callback, ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => 'callback = "useCallback"
@module("react")
external useContext: Context.t<'any> => 'any = "useContext"
@module("react") external useRef: 'value => ref<'value> = "useRef"
@module("react")
external useImperativeHandleOnEveryRender: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
'deps,
) => unit = "useImperativeHandle"
@module("react")
@deprecated("Please use useImperativeHandle or useImperativeHandleOnEveryRender instead")
external useImperativeHandle0: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
@as(json`[]`) _,
) => unit = "useImperativeHandle"
@module("react")
@deprecated("Please use useImperativeHandle or useImperativeHandleOnEveryRender instead")
external useImperativeHandle1: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
array<'a>,
) => unit = "useImperativeHandle"
@module("react")
@deprecated("Please use useImperativeHandle or useImperativeHandleOnEveryRender instead")
external useImperativeHandle2: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b),
) => unit = "useImperativeHandle"
@module("react")
@deprecated("Please use useImperativeHandle or useImperativeHandleOnEveryRender instead")
external useImperativeHandle3: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b, 'c),
) => unit = "useImperativeHandle"
@module("react")
@deprecated("Please use useImperativeHandle or useImperativeHandleOnEveryRender instead")
external useImperativeHandle4: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b, 'c, 'd),
) => unit = "useImperativeHandle"
@module("react")
@deprecated("Please use useImperativeHandle or useImperativeHandleOnEveryRender instead")
external useImperativeHandle5: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b, 'c, 'd, 'e),
) => unit = "useImperativeHandle"
@module("react")
@deprecated("Please use useImperativeHandle or useImperativeHandleOnEveryRender instead")
external useImperativeHandle6: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b, 'c, 'd, 'e, 'f),
) => unit = "useImperativeHandle"
@module("react")
@deprecated("Please use useImperativeHandle or useImperativeHandleOnEveryRender instead")
external useImperativeHandle7: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b, 'c, 'd, 'e, 'f, 'g),
) => unit = "useImperativeHandle"
@module("react") external useId: unit => string = "useId"
@module("react") external useDeferredValue: 'value => 'value = "useDeferredValue"
@module("react")
external useTransition: unit => (bool, (. unit => unit) => unit) = "useTransition"
@module("react")
external useInsertionEffectOnEveryRender: (@uncurry (unit => option<unit => unit>)) => unit =
"useInsertionEffect"
@module("react")
external useInsertionEffect: (@uncurry (unit => option<unit => unit>), 'deps) => unit =
"useInsertionEffect"
@module("react")
@deprecated("Please use useInsertionEffect or useInsertionEffectOnEveryRender instead")
external useInsertionEffect0: (@uncurry (unit => option<unit => unit>), @as(json`[]`) _) => unit =
"useInsertionEffect"
@module("react")
@deprecated("Please use useInsertionEffect or useInsertionEffectOnEveryRender instead")
external useInsertionEffect1: (@uncurry (unit => option<unit => unit>), array<'a>) => unit =
"useInsertionEffect"
@module("react")
@deprecated("Please use useInsertionEffect or useInsertionEffectOnEveryRender instead")
external useInsertionEffect2: (@uncurry (unit => option<unit => unit>), ('a, 'b)) => unit =
"useInsertionEffect"
@module("react")
@deprecated("Please use useInsertionEffect or useInsertionEffectOnEveryRender instead")
external useInsertionEffect3: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c)) => unit =
"useInsertionEffect"
@module("react")
@deprecated("Please use useInsertionEffect or useInsertionEffectOnEveryRender instead")
external useInsertionEffect4: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd)) => unit =
"useInsertionEffect"
@module("react")
@deprecated("Please use useInsertionEffect or useInsertionEffectOnEveryRender instead")
external useInsertionEffect5: (
@uncurry (unit => option<unit => unit>),
('a, 'b, 'c, 'd, 'e),
) => unit = "useInsertionEffect"
@module("react")
@deprecated("Please use useInsertionEffect or useInsertionEffectOnEveryRender instead")
external useInsertionEffect6: (
@uncurry (unit => option<unit => unit>),
('a, 'b, 'c, 'd, 'e, 'f),
) => unit = "useInsertionEffect"
@module("react")
@deprecated("Please use useInsertionEffect or useInsertionEffectOnEveryRender instead")
external useInsertionEffect7: (
@uncurry (unit => option<unit => unit>),
('a, 'b, 'c, 'd, 'e, 'f, 'g),
) => unit = "useInsertionEffect"
@module("react")
external useSyncExternalStore: (
~subscribe: @uncurry ((unit => unit) => (. unit) => unit),
~getSnapshot: @uncurry unit => 'state,
) => 'state = "useSyncExternalStore"
@module("react")
external useSyncExternalStoreWithServerSnapshot: (
~subscribe: @uncurry ((unit => unit) => (. unit) => unit),
~getSnapshot: @uncurry unit => 'state,
~getServerSnapshot: @uncurry unit => 'state,
) => 'state = "useSyncExternalStore"
module Uncurried = {
@module("react")
external useState: (@uncurry (unit => 'state)) => ('state, (. 'state => 'state) => unit) =
"useState"
@module("react")
external useReducer: (
@uncurry ('state, 'action) => 'state,
'state,
) => ('state, (. 'action) => unit) = "useReducer"
@module("react")
external useReducerWithMapState: (
@uncurry ('state, 'action) => 'state,
'initialState,
@uncurry ('initialState => 'state),
) => ('state, (. 'action) => unit) = "useReducer"
@module("react")
external useCallback: ('f, 'deps) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback0: ('f, @as(json`[]`) _) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback1: ('f, array<'a>) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback2: ('f, ('a, 'b)) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback3: ('f, ('a, 'b, 'c)) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback4: ('f, ('a, 'b, 'c, 'd)) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback5: ('f, ('a, 'b, 'c, 'd, 'e)) => 'f = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback6: ('callback, ('a, 'b, 'c, 'd, 'e, 'f)) => 'callback = "useCallback"
@module("react") @deprecated("Please use useCallback instead")
external useCallback7: ('callback, ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => 'callback = "useCallback"
}
@set
external setDisplayName: (component<'props>, string) => unit = "displayName"
@get @return(nullable)
external displayName: component<'props> => option<string> = "displayName"