/
React.res
451 lines (368 loc) · 13.3 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
type 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> = 'props => 'return
type component<'props> = componentLike<'props, element>
/* this function exists to prepare for making `component` abstract */
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"
@variadic @module("react")
external createElementVariadic: (component<'props>, 'props, array<element>) => element =
"createElement"
@module("react") @deprecated("Please use JSX syntax directly.")
external jsxKeyed: (component<'props>, 'props, string) => element = "jsx"
@module("react") @deprecated("Please use JSX syntax directly.")
external jsx: (component<'props>, 'props) => element = "jsx"
@module("react") @deprecated("Please use JSX syntax directly.")
external jsxs: (component<'props>, 'props) => element = "jsxs"
@module("react") @deprecated("Please use JSX syntax directly.")
external jsxsKeyed: (component<'props>, 'props, string) => element = "jsxs"
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<'props>
@obj
external makeProps: (
~value: 'props,
~children: element,
unit,
) => {"value": 'props, "children": element} = ""
@get
external provider: t<'props> => component<{"value": 'props, "children": element}> = "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 Fragment = {
@obj
external makeProps: (~children: element, ~key: 'key=?, unit) => {"children": element} = ""
@module("react")
external make: component<{
"children": element,
}> = "Fragment"
}
module StrictMode = {
@obj
external makeProps: (~children: element, ~key: 'key=?, unit) => {"children": element} = ""
@module("react")
external make: component<{
"children": element,
}> = "StrictMode"
}
module Suspense = {
@obj
external makeProps: (
~children: element=?,
~fallback: element=?,
~key: 'key=?,
unit,
) => {"children": option<element>, "fallback": option<element>} = ""
@module("react")
external make: component<{
"children": option<element>,
"fallback": option<element>,
}> = "Suspense"
}
module Experimental = {
module SuspenseList = {
type revealOrder
type tail
@obj
external makeProps: (
~children: element=?,
~revealOrder: [#forwards | #backwards | #together]=?,
~tail: [#collapsed | #hidden]=?,
unit,
) => {"children": option<element>, "revealOrder": option<revealOrder>, "tail": option<tail>} =
""
@module("react")
external make: component<{
"children": option<element>,
"revealOrder": option<revealOrder>,
"tail": option<tail>,
}> = "SuspenseList"
}
}
/* 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 useEffect: (@uncurry (unit => option<unit => unit>)) => unit = "useEffect"
@module("react")
external useEffect0: (@uncurry (unit => option<unit => unit>), @as(json`[]`) _) => unit =
"useEffect"
@module("react")
external useEffect1: (@uncurry (unit => option<unit => unit>), array<'a>) => unit = "useEffect"
@module("react")
external useEffect2: (@uncurry (unit => option<unit => unit>), ('a, 'b)) => unit = "useEffect"
@module("react")
external useEffect3: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c)) => unit = "useEffect"
@module("react")
external useEffect4: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd)) => unit =
"useEffect"
@module("react")
external useEffect5: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd, 'e)) => unit =
"useEffect"
@module("react")
external useEffect6: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd, 'e, 'f)) => unit =
"useEffect"
@module("react")
external useEffect7: (
@uncurry (unit => option<unit => unit>),
('a, 'b, 'c, 'd, 'e, 'f, 'g),
) => unit = "useEffect"
@module("react")
external useLayoutEffect: (@uncurry (unit => option<unit => unit>)) => unit = "useLayoutEffect"
@module("react")
external useLayoutEffect0: (@uncurry (unit => option<unit => unit>), @as(json`[]`) _) => unit =
"useLayoutEffect"
@module("react")
external useLayoutEffect1: (@uncurry (unit => option<unit => unit>), array<'a>) => unit =
"useLayoutEffect"
@module("react")
external useLayoutEffect2: (@uncurry (unit => option<unit => unit>), ('a, 'b)) => unit =
"useLayoutEffect"
@module("react")
external useLayoutEffect3: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c)) => unit =
"useLayoutEffect"
@module("react")
external useLayoutEffect4: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd)) => unit =
"useLayoutEffect"
@module("react")
external useLayoutEffect5: (@uncurry (unit => option<unit => unit>), ('a, 'b, 'c, 'd, 'e)) => unit =
"useLayoutEffect"
@module("react")
external useLayoutEffect6: (
@uncurry (unit => option<unit => unit>),
('a, 'b, 'c, 'd, 'e, 'f),
) => unit = "useLayoutEffect"
@module("react")
external useLayoutEffect7: (
@uncurry (unit => option<unit => unit>),
('a, 'b, 'c, 'd, 'e, 'f, 'g),
) => unit = "useLayoutEffect"
@module("react")
external useMemo: (@uncurry (unit => 'any)) => 'any = "useMemo"
@module("react")
external useMemo0: (@uncurry (unit => 'any), @as(json`[]`) _) => 'any = "useMemo"
@module("react")
external useMemo1: (@uncurry (unit => 'any), array<'a>) => 'any = "useMemo"
@module("react")
external useMemo2: (@uncurry (unit => 'any), ('a, 'b)) => 'any = "useMemo"
@module("react")
external useMemo3: (@uncurry (unit => 'any), ('a, 'b, 'c)) => 'any = "useMemo"
@module("react")
external useMemo4: (@uncurry (unit => 'any), ('a, 'b, 'c, 'd)) => 'any = "useMemo"
@module("react")
external useMemo5: (@uncurry (unit => 'any), ('a, 'b, 'c, 'd, 'e)) => 'any = "useMemo"
@module("react")
external useMemo6: (@uncurry (unit => 'any), ('a, 'b, 'c, 'd, 'e, 'f)) => 'any = "useMemo"
@module("react")
external useMemo7: (@uncurry (unit => 'any), ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => 'any = "useMemo"
/* This is used as return values */
type callback<'input, 'output> = 'input => 'output
@module("react")
external useCallback: (@uncurry ('input => 'output)) => callback<'input, 'output> = "useCallback"
@module("react")
external useCallback0: (
@uncurry ('input => 'output),
@as(json`[]`) _,
) => callback<'input, 'output> = "useCallback"
@module("react")
external useCallback1: (@uncurry ('input => 'output), array<'a>) => callback<'input, 'output> =
"useCallback"
@module("react")
external useCallback2: (@uncurry ('input => 'output), ('a, 'b)) => callback<'input, 'output> =
"useCallback"
@module("react")
external useCallback3: (@uncurry ('input => 'output), ('a, 'b, 'c)) => callback<'input, 'output> =
"useCallback"
@module("react")
external useCallback4: (
@uncurry ('input => 'output),
('a, 'b, 'c, 'd),
) => callback<'input, 'output> = "useCallback"
@module("react")
external useCallback5: (
@uncurry ('input => 'output),
('a, 'b, 'c, 'd, 'e),
) => callback<'input, 'output> = "useCallback"
@module("react")
external useCallback6: (
@uncurry ('input => 'output),
('a, 'b, 'c, 'd, 'e, 'f),
) => callback<'input, 'output> = "useCallback"
@module("react")
external useCallback7: (
@uncurry ('input => 'output),
('a, 'b, 'c, 'd, 'e, 'f, 'g),
) => callback<'input, 'output> = "useCallback"
@module("react")
external useContext: Context.t<'any> => 'any = "useContext"
@module("react") external useRef: 'value => ref<'value> = "useRef"
@module("react")
external useImperativeHandle0: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
@as(json`[]`) _,
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle1: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
array<'a>,
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle2: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b),
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle3: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b, 'c),
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle4: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b, 'c, 'd),
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle5: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b, 'c, 'd, 'e),
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle6: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b, 'c, 'd, 'e, 'f),
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle7: (
Js.Nullable.t<ref<'value>>,
@uncurry (unit => 'value),
('a, 'b, 'c, 'd, 'e, 'f, 'g),
) => unit = "useImperativeHandle"
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"
type callback<'input, 'output> = (. 'input) => 'output
@module("react")
external useCallback: (@uncurry ('input => 'output)) => callback<'input, 'output> = "useCallback"
@module("react")
external useCallback0: (
@uncurry ('input => 'output),
@as(json`[]`) _,
) => callback<'input, 'output> = "useCallback"
@module("react")
external useCallback1: (@uncurry ('input => 'output), array<'a>) => callback<'input, 'output> =
"useCallback"
@module("react")
external useCallback2: (@uncurry ('input => 'output), ('a, 'b)) => callback<'input, 'output> =
"useCallback"
@module("react")
external useCallback3: (@uncurry ('input => 'output), ('a, 'b, 'c)) => callback<'input, 'output> =
"useCallback"
@module("react")
external useCallback4: (
@uncurry ('input => 'output),
('a, 'b, 'c, 'd),
) => callback<'input, 'output> = "useCallback"
@module("react")
external useCallback5: (
@uncurry ('input => 'output),
('a, 'b, 'c, 'd, 'e),
) => callback<'input, 'output> = "useCallback"
@module("react")
external useCallback6: (
@uncurry ('input => 'output),
('a, 'b, 'c, 'd, 'e, 'f),
) => callback<'input, 'output> = "useCallback"
@module("react")
external useCallback7: (
@uncurry ('input => 'output),
('a, 'b, 'c, 'd, 'e, 'f, 'g),
) => callback<'input, 'output> = "useCallback"
}
type transitionConfig = {timeoutMs: int}
@module("react")
external useTransition: (
~config: transitionConfig=?,
unit,
) => (callback<callback<unit, unit>, unit>, bool) = "useTransition"
@set
external setDisplayName: (component<'props>, string) => unit = "displayName"
@get @return(nullable)
external displayName: component<'props> => option<string> = "displayName"