@@ -14,13 +14,20 @@ type component<'props> = Jsx.component<'props>
14
14
15
15
let component = Jsx .component
16
16
17
+ %%private (
18
+ @inline
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
+ }
24
+ )
25
+
17
26
@module ("react" )
18
27
external createElement : (component <'props >, 'props ) => element = "createElement"
19
28
20
- let createElementWithKey = (~key = ?, component , props ) => {
21
- let _ = Obj .magic (props )["key" ] = key
22
- createElement (component , props )
23
- }
29
+ let createElementWithKey = (~key = ?, component , props ) =>
30
+ createElement (component , addKeyProp (~key ?, props ))
24
31
25
32
@module ("react" )
26
33
external cloneElement : (element , 'props ) => element = "cloneElement"
@@ -32,10 +39,8 @@ external isValidElement: 'a => bool = "isValidElement"
32
39
external createElementVariadic : (component <'props >, 'props , array <element >) => element =
33
40
"createElement"
34
41
35
- let createElementVariadicWithKey = (~key = ?, component , props , elements ) => {
36
- let _ = Obj .magic (props )["key" ] = key
37
- createElementVariadic (component , props , elements )
38
- }
42
+ let createElementVariadicWithKey = (~key = ?, component , props , elements ) =>
43
+ createElementVariadic (component , addKeyProp (~key ?, props ), elements )
39
44
40
45
@module ("react/jsx-runtime" )
41
46
external jsxNotKeyed : (component <'props >, 'props ) => element = "jsx"
0 commit comments