Skip to content

Commit fb232ec

Browse files
authored
Fix key prop type (#74)
* fix-key-type * rename jsx binding * fix key type for ReactDOM jsx runtime * update changelog * add key imperatively * Revert "add key imperatively" This reverts commit 2f48356. * change jsx runtime binding * update changelog
1 parent e4e3080 commit fb232ec

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.11.0-rc.3
4+
5+
- Changed `React.jsxKeyed(s)`, `ReactDOM.jsxKeyed(s)` having key as optional argument.
6+
37
## 0.11.0-rc.2
48

59
- Fixed JSX PPX V3 backward compatibility.

src/React.bs.js

Lines changed: 8 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: 14 additions & 11 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,20 +39,20 @@ 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")
43-
external jsxKeyed: (component<'props>, 'props, string) => element = "jsx"
46+
external jsx: (component<'props>, 'props) => element = "jsx"
4447

4548
@module("react/jsx-runtime")
46-
external jsx: (component<'props>, 'props) => element = "jsx"
49+
external jsxKeyed: (component<'props>, 'props, ~key: string=?, @ignore unit) => element = "jsx"
4750

4851
@module("react/jsx-runtime")
4952
external jsxs: (component<'props>, 'props) => element = "jsxs"
5053

5154
@module("react/jsx-runtime")
52-
external jsxsKeyed: (component<'props>, 'props, string) => element = "jsxs"
55+
external jsxsKeyed: (component<'props>, 'props, ~key: string=?, @ignore unit) => element = "jsxs"
5356

5457
type fragmentProps<'children> = {children: 'children}
5558

@@ -413,13 +416,13 @@ external useInsertionEffect7: (
413416

414417
@module("react")
415418
external useSyncExternalStore: (
416-
~subscribe: @uncurry ((unit => unit) => ((. unit) => unit)),
419+
~subscribe: @uncurry (unit => unit, . unit) => unit,
417420
~getSnapshot: @uncurry unit => 'state,
418421
) => 'state = "useSyncExternalStore"
419422

420423
@module("react")
421424
external useSyncExternalStoreWithServerSnapshot: (
422-
~subscribe: @uncurry ((unit => unit) => ((. unit) => unit)),
425+
~subscribe: @uncurry (unit => unit, . unit) => unit,
423426
~getSnapshot: @uncurry unit => 'state,
424427
~getServerSnapshot: @uncurry unit => 'state,
425428
) => 'state = "useSyncExternalStore"

src/ReactDOM.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,16 +1109,16 @@ external createDOMElementVariadic: (
11091109
external someElement: React.element => option<React.element> = "%identity"
11101110

11111111
@module("react/jsx-runtime")
1112-
external jsxKeyed: (string, JsxDOM.domProps, string) => Jsx.element = "jsx"
1112+
external jsx: (string, JsxDOM.domProps) => Jsx.element = "jsx"
11131113

11141114
@module("react/jsx-runtime")
1115-
external jsx: (string, JsxDOM.domProps) => Jsx.element = "jsx"
1115+
external jsxKeyed: (string, JsxDOM.domProps, ~key: string=?, @ignore unit) => Jsx.element = "jsx"
11161116

11171117
@module("react/jsx-runtime")
11181118
external jsxs: (string, JsxDOM.domProps) => Jsx.element = "jsxs"
11191119

11201120
@module("react/jsx-runtime")
1121-
external jsxsKeyed: (string, JsxDOM.domProps, string) => Jsx.element = "jsxs"
1121+
external jsxsKeyed: (string, JsxDOM.domProps, ~key: string=?, @ignore unit) => Jsx.element = "jsxs"
11221122

11231123
// Currently, not used by JSX ppx
11241124
@deprecated("Please use ReactDOM.createElement instead.")

0 commit comments

Comments
 (0)