Skip to content

Fix key prop type #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "add key imperatively"
This reverts commit 2f48356.
  • Loading branch information
mununki committed Oct 23, 2022
commit 3f0f2e969746300968a3a8ac3cc25f8b91dc716f
10 changes: 6 additions & 4 deletions src/React.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions src/React.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ type component<'props> = Jsx.component<'props>

let component = Jsx.component

%%private(
@inline
let addKeyProp = (~key: option<string>=?, p: 'props): 'props =>
switch key {
| Some(key) => Obj.magic(Js.Obj.assign(Obj.magic(p), {"key": key}))
| None => p
}
)

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

let createElementWithKey = (~key=?, component, props) => {
let _ = Obj.magic(props)["key"] = key
createElement(component, props)
}
let createElementWithKey = (~key=?, component, props) =>
createElement(component, addKeyProp(~key?, props))

@module("react")
external cloneElement: (element, 'props) => element = "cloneElement"
Expand All @@ -32,10 +39,8 @@ external isValidElement: 'a => bool = "isValidElement"
external createElementVariadic: (component<'props>, 'props, array<element>) => element =
"createElement"

let createElementVariadicWithKey = (~key=?, component, props, elements) => {
let _ = Obj.magic(props)["key"] = key
createElementVariadic(component, props, elements)
}
let createElementVariadicWithKey = (~key=?, component, props, elements) =>
createElementVariadic(component, addKeyProp(~key?, props), elements)

@module("react/jsx-runtime")
external jsxNotKeyed: (component<'props>, 'props) => element = "jsx"
Expand Down