@@ -16,15 +16,18 @@ let component = Jsx.component
16
16
17
17
%%private (
18
18
@inline
19
- let addKeyProp = (p : 'props , k : string ): 'props =>
20
- Obj .magic (Js .Obj .assign (Obj .magic (p ), {"key" : k }))
19
+ let addKeyProp = (~key : option <string >= ?, p : 'props ): 'props =>
20
+ switch key {
21
+ | Some (key ) => Obj .magic (Js .Obj .assign (Obj .magic (p ), {"key" : key }))
22
+ | None => p
23
+ }
21
24
)
22
25
23
26
@module ("react" )
24
27
external createElement : (component <'props >, 'props ) => element = "createElement"
25
28
26
- let createElementWithKey = (component , props , key ) =>
27
- createElement (component , addKeyProp (props , key ))
29
+ let createElementWithKey = (~ key = ?, component , props ) =>
30
+ createElement (component , addKeyProp (~ key ?, props ))
28
31
29
32
@module ("react" )
30
33
external cloneElement : (element , 'props ) => element = "cloneElement"
@@ -36,21 +39,33 @@ external isValidElement: 'a => bool = "isValidElement"
36
39
external createElementVariadic : (component <'props >, 'props , array <element >) => element =
37
40
"createElement"
38
41
39
- let createElementVariadicWithKey = (component , props , elements , key ) =>
40
- createElementVariadic (component , addKeyProp (props , key ), elements )
42
+ let createElementVariadicWithKey = (~ key = ?, component , props , elements ) =>
43
+ createElementVariadic (component , addKeyProp (~ key ?, props ), elements )
41
44
42
45
@module ("react/jsx-runtime" )
43
46
external jsxKeyed : (component <'props >, 'props , string ) => element = "jsx"
44
47
45
48
@module ("react/jsx-runtime" )
46
49
external jsx : (component <'props >, 'props ) => element = "jsx"
47
50
51
+ let jsxWithKey = (~key = ?, component , props ) =>
52
+ switch key {
53
+ | Some (key ) => jsxKeyed (component , props , key )
54
+ | None => jsx (component , props )
55
+ }
56
+
48
57
@module ("react/jsx-runtime" )
49
58
external jsxs : (component <'props >, 'props ) => element = "jsxs"
50
59
51
60
@module ("react/jsx-runtime" )
52
61
external jsxsKeyed : (component <'props >, 'props , string ) => element = "jsxs"
53
62
63
+ let jsxsWithKey = (~key = ?, component , props ) =>
64
+ switch key {
65
+ | Some (key ) => jsxsKeyed (component , props , key )
66
+ | None => jsxs (component , props )
67
+ }
68
+
54
69
type fragmentProps <'children > = {children : 'children }
55
70
56
71
@module ("react/jsx-runtime" ) external jsxFragment : component <fragmentProps <'children >> = "Fragment"
@@ -413,13 +428,13 @@ external useInsertionEffect7: (
413
428
414
429
@module ("react" )
415
430
external useSyncExternalStore : (
416
- ~subscribe : @uncurry (( unit => unit ) => (( . unit ) => unit )) ,
431
+ ~subscribe : @uncurry (unit => unit , . unit ) => unit ,
417
432
~getSnapshot : @uncurry unit => 'state ,
418
433
) => 'state = "useSyncExternalStore"
419
434
420
435
@module ("react" )
421
436
external useSyncExternalStoreWithServerSnapshot : (
422
- ~subscribe : @uncurry (( unit => unit ) => (( . unit ) => unit )) ,
437
+ ~subscribe : @uncurry (unit => unit , . unit ) => unit ,
423
438
~getSnapshot : @uncurry unit => 'state ,
424
439
~getServerSnapshot : @uncurry unit => 'state ,
425
440
) => 'state = "useSyncExternalStore"
0 commit comments