-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathReact.res
407 lines (315 loc) · 13 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
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("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, (element, int) => element) => element = "map"
@module("react") @scope("Children")
external forEach: (element, element => unit) => unit = "forEach"
@module("react") @scope("Children")
external forEachWithIndex: (element, (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: (('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>,
('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: (unit => 'state) => ('state, ('state => 'state) => unit) = "useState"
@module("react")
external useReducer: (('state, 'action) => 'state, 'state) => ('state, 'action => unit) =
"useReducer"
@module("react")
external useReducerWithMapState: (
('state, 'action) => 'state,
'initialState,
'initialState => 'state,
) => ('state, 'action => unit) = "useReducer"
@module("react")
external useEffectOnEveryRender: (unit => option<unit => unit>) => unit = "useEffect"
@module("react")
external useEffect: (unit => option<unit => unit>, 'deps) => unit = "useEffect"
@module("react")
external useEffect0: (unit => option<unit => unit>, @as(json`[]`) _) => unit = "useEffect"
@module("react")
external useEffect1: (unit => option<unit => unit>, array<'a>) => unit = "useEffect"
@module("react")
external useEffect2: (unit => option<unit => unit>, ('a, 'b)) => unit = "useEffect"
@module("react")
external useEffect3: (unit => option<unit => unit>, ('a, 'b, 'c)) => unit = "useEffect"
@module("react")
external useEffect4: (unit => option<unit => unit>, ('a, 'b, 'c, 'd)) => unit = "useEffect"
@module("react")
external useEffect5: (unit => option<unit => unit>, ('a, 'b, 'c, 'd, 'e)) => unit = "useEffect"
@module("react")
external useEffect6: (unit => option<unit => unit>, ('a, 'b, 'c, 'd, 'e, 'f)) => unit = "useEffect"
@module("react")
external useEffect7: (unit => option<unit => unit>, ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => unit =
"useEffect"
@module("react")
external useLayoutEffectOnEveryRender: (unit => option<unit => unit>) => unit = "useLayoutEffect"
@module("react")
external useLayoutEffect: (unit => option<unit => unit>, 'deps) => unit = "useLayoutEffect"
@module("react")
external useLayoutEffect0: (unit => option<unit => unit>, @as(json`[]`) _) => unit =
"useLayoutEffect"
@module("react")
external useLayoutEffect1: (unit => option<unit => unit>, array<'a>) => unit = "useLayoutEffect"
@module("react")
external useLayoutEffect2: (unit => option<unit => unit>, ('a, 'b)) => unit = "useLayoutEffect"
@module("react")
external useLayoutEffect3: (unit => option<unit => unit>, ('a, 'b, 'c)) => unit = "useLayoutEffect"
@module("react")
external useLayoutEffect4: (unit => option<unit => unit>, ('a, 'b, 'c, 'd)) => unit =
"useLayoutEffect"
@module("react")
external useLayoutEffect5: (unit => option<unit => unit>, ('a, 'b, 'c, 'd, 'e)) => unit =
"useLayoutEffect"
@module("react")
external useLayoutEffect6: (unit => option<unit => unit>, ('a, 'b, 'c, 'd, 'e, 'f)) => unit =
"useLayoutEffect"
@module("react")
external useLayoutEffect7: (unit => option<unit => unit>, ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => unit =
"useLayoutEffect"
@module("react")
external useMemo: (unit => 'any, 'deps) => 'any = "useMemo"
@module("react")
external useMemo0: (unit => 'any, @as(json`[]`) _) => 'any = "useMemo"
@module("react")
external useMemo1: (unit => 'any, array<'a>) => 'any = "useMemo"
@module("react")
external useMemo2: (unit => 'any, ('a, 'b)) => 'any = "useMemo"
@module("react")
external useMemo3: (unit => 'any, ('a, 'b, 'c)) => 'any = "useMemo"
@module("react")
external useMemo4: (unit => 'any, ('a, 'b, 'c, 'd)) => 'any = "useMemo"
@module("react")
external useMemo5: (unit => 'any, ('a, 'b, 'c, 'd, 'e)) => 'any = "useMemo"
@module("react")
external useMemo6: (unit => 'any, ('a, 'b, 'c, 'd, 'e, 'f)) => 'any = "useMemo"
@module("react")
external useMemo7: (unit => 'any, ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => 'any = "useMemo"
@module("react")
external useCallback: ('f, 'deps) => 'f = "useCallback"
@module("react")
external useCallback0: ('f, @as(json`[]`) _) => 'f = "useCallback"
@module("react")
external useCallback1: ('f, array<'a>) => 'f = "useCallback"
@module("react")
external useCallback2: ('f, ('a, 'b)) => 'f = "useCallback"
@module("react")
external useCallback3: ('f, ('a, 'b, 'c)) => 'f = "useCallback"
@module("react")
external useCallback4: ('f, ('a, 'b, 'c, 'd)) => 'f = "useCallback"
@module("react")
external useCallback5: ('f, ('a, 'b, 'c, 'd, 'e)) => 'f = "useCallback"
@module("react")
external useCallback6: ('callback, ('a, 'b, 'c, 'd, 'e, 'f)) => 'callback = "useCallback"
@module("react")
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>>, unit => 'value) => unit =
"useImperativeHandle"
@module("react")
external useImperativeHandle: (Js.Nullable.t<ref<'value>>, unit => 'value, 'deps) => unit =
"useImperativeHandle"
@module("react")
external useImperativeHandle0: (
Js.Nullable.t<ref<'value>>,
unit => 'value,
@as(json`[]`) _,
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle1: (Js.Nullable.t<ref<'value>>, unit => 'value, array<'a>) => unit =
"useImperativeHandle"
@module("react")
external useImperativeHandle2: (Js.Nullable.t<ref<'value>>, unit => 'value, ('a, 'b)) => unit =
"useImperativeHandle"
@module("react")
external useImperativeHandle3: (Js.Nullable.t<ref<'value>>, unit => 'value, ('a, 'b, 'c)) => unit =
"useImperativeHandle"
@module("react")
external useImperativeHandle4: (
Js.Nullable.t<ref<'value>>,
unit => 'value,
('a, 'b, 'c, 'd),
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle5: (
Js.Nullable.t<ref<'value>>,
unit => 'value,
('a, 'b, 'c, 'd, 'e),
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle6: (
Js.Nullable.t<ref<'value>>,
unit => 'value,
('a, 'b, 'c, 'd, 'e, 'f),
) => unit = "useImperativeHandle"
@module("react")
external useImperativeHandle7: (
Js.Nullable.t<ref<'value>>,
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: (unit => option<unit => unit>) => unit =
"useInsertionEffect"
@module("react")
external useInsertionEffect: (unit => option<unit => unit>, 'deps) => unit = "useInsertionEffect"
@module("react")
external useInsertionEffect0: (unit => option<unit => unit>, @as(json`[]`) _) => unit =
"useInsertionEffect"
@module("react")
external useInsertionEffect1: (unit => option<unit => unit>, array<'a>) => unit =
"useInsertionEffect"
@module("react")
external useInsertionEffect2: (unit => option<unit => unit>, ('a, 'b)) => unit =
"useInsertionEffect"
@module("react")
external useInsertionEffect3: (unit => option<unit => unit>, ('a, 'b, 'c)) => unit =
"useInsertionEffect"
@module("react")
external useInsertionEffect4: (unit => option<unit => unit>, ('a, 'b, 'c, 'd)) => unit =
"useInsertionEffect"
@module("react")
external useInsertionEffect5: (unit => option<unit => unit>, ('a, 'b, 'c, 'd, 'e)) => unit =
"useInsertionEffect"
@module("react")
external useInsertionEffect6: (unit => option<unit => unit>, ('a, 'b, 'c, 'd, 'e, 'f)) => unit =
"useInsertionEffect"
@module("react")
external useInsertionEffect7: (unit => option<unit => unit>, ('a, 'b, 'c, 'd, 'e, 'f, 'g)) => unit =
"useInsertionEffect"
@module("react")
external useSyncExternalStore: (
~subscribe: (unit => unit) => unit => unit,
~getSnapshot: unit => 'state,
) => 'state = "useSyncExternalStore"
@module("react")
external useSyncExternalStoreWithServerSnapshot: (
~subscribe: (unit => unit) => unit => unit,
~getSnapshot: unit => 'state,
~getServerSnapshot: unit => 'state,
) => 'state = "useSyncExternalStore"
module Uncurried = {
@module("react")
external useState: (unit => 'state) => ('state, ('state => 'state) => unit) = "useState"
@module("react")
external useReducer: (('state, 'action) => 'state, 'state) => ('state, 'action => unit) =
"useReducer"
@module("react")
external useReducerWithMapState: (
('state, 'action) => 'state,
'initialState,
'initialState => 'state,
) => ('state, 'action => unit) = "useReducer"
@module("react")
external useCallback: ('f, 'deps) => 'f = "useCallback"
@module("react")
external useCallback0: ('f, @as(json`[]`) _) => 'f = "useCallback"
@module("react")
external useCallback1: ('f, array<'a>) => 'f = "useCallback"
@module("react")
external useCallback2: ('f, ('a, 'b)) => 'f = "useCallback"
@module("react")
external useCallback3: ('f, ('a, 'b, 'c)) => 'f = "useCallback"
@module("react")
external useCallback4: ('f, ('a, 'b, 'c, 'd)) => 'f = "useCallback"
@module("react")
external useCallback5: ('f, ('a, 'b, 'c, 'd, 'e)) => 'f = "useCallback"
@module("react")
external useCallback6: ('callback, ('a, 'b, 'c, 'd, 'e, 'f)) => 'callback = "useCallback"
@module("react")
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"