Skip to content

Commit 5e09771

Browse files
committed
fix-key-type
1 parent e4e3080 commit 5e09771

File tree

2 files changed

+50
-16
lines changed

2 files changed

+50
-16
lines changed

src/React.bs.js

Lines changed: 27 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/React.res

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ let component = Jsx.component
1616

1717
%%private(
1818
@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+
}
2124
)
2225

2326
@module("react")
2427
external createElement: (component<'props>, 'props) => element = "createElement"
2528

26-
let createElementWithKey = (component, props, key) =>
27-
createElement(component, addKeyProp(props, key))
29+
let createElementWithKey = (~key=?, component, props) =>
30+
createElement(component, addKeyProp(~key?, props))
2831

2932
@module("react")
3033
external cloneElement: (element, 'props) => element = "cloneElement"
@@ -36,21 +39,33 @@ external isValidElement: 'a => bool = "isValidElement"
3639
external createElementVariadic: (component<'props>, 'props, array<element>) => element =
3740
"createElement"
3841

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)
4144

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

4548
@module("react/jsx-runtime")
4649
external jsx: (component<'props>, 'props) => element = "jsx"
4750

51+
let jsxWithKey = (~key=?, component, props) =>
52+
switch key {
53+
| Some(key) => jsxKeyed(component, props, key)
54+
| None => jsx(component, props)
55+
}
56+
4857
@module("react/jsx-runtime")
4958
external jsxs: (component<'props>, 'props) => element = "jsxs"
5059

5160
@module("react/jsx-runtime")
5261
external jsxsKeyed: (component<'props>, 'props, string) => element = "jsxs"
5362

63+
let jsxsWithKey = (~key=?, component, props) =>
64+
switch key {
65+
| Some(key) => jsxsKeyed(component, props, key)
66+
| None => jsxs(component, props)
67+
}
68+
5469
type fragmentProps<'children> = {children: 'children}
5570

5671
@module("react/jsx-runtime") external jsxFragment: component<fragmentProps<'children>> = "Fragment"
@@ -413,13 +428,13 @@ external useInsertionEffect7: (
413428

414429
@module("react")
415430
external useSyncExternalStore: (
416-
~subscribe: @uncurry ((unit => unit) => ((. unit) => unit)),
431+
~subscribe: @uncurry (unit => unit, . unit) => unit,
417432
~getSnapshot: @uncurry unit => 'state,
418433
) => 'state = "useSyncExternalStore"
419434

420435
@module("react")
421436
external useSyncExternalStoreWithServerSnapshot: (
422-
~subscribe: @uncurry ((unit => unit) => ((. unit) => unit)),
437+
~subscribe: @uncurry (unit => unit, . unit) => unit,
423438
~getSnapshot: @uncurry unit => 'state,
424439
~getServerSnapshot: @uncurry unit => 'state,
425440
) => 'state = "useSyncExternalStore"

0 commit comments

Comments
 (0)