Skip to content

Commit 32809fc

Browse files
committed
add addKeyProp
1 parent 814101b commit 32809fc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/React.res

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ type component<'props> = Jsx.component<'props>
1414

1515
let component = Jsx.component
1616

17+
/** Use Js_obj.assign, not Js.Obj.assign, otherwise the dependency will not be picked up correctly
18+
in the ninja file. */
19+
@inline
20+
let addKeyProp = (p: 'props, k: string): 'props =>
21+
Obj.magic(Js.Obj.assign(Obj.magic(p), {"key": k}))
22+
1723
@module("react")
1824
external createElement: (component<'props>, 'props) => element = "createElement"
1925

2026
let createElementWithKey = (component, props, key) =>
21-
createElement(component, Jsx.addKeyProp(props, key))
27+
createElement(component, addKeyProp(props, key))
2228

2329
@module("react")
2430
external cloneElement: (element, 'props) => element = "cloneElement"
@@ -28,7 +34,7 @@ external createElementVariadic: (component<'props>, 'props, array<element>) => e
2834
"createElement"
2935

3036
let createElementVariadicWithKey = (component, props, elements, key) =>
31-
createElementVariadic(component, Jsx.addKeyProp(props, key), elements)
37+
createElementVariadic(component, addKeyProp(props, key), elements)
3238

3339
@module("react/jsx-runtime")
3440
external jsxKeyed: (component<'props>, 'props, string) => element = "jsx"

0 commit comments

Comments
 (0)