-
Notifications
You must be signed in to change notification settings - Fork 38
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- add a line to the changelog
- how about
JSXV4.md
, does it need updating? - how about adding an example with
?key
@@ -36,4 +36,4 @@ module Foo = { | |||
external component: React.componentLike<props<int, string>, React.element> = "component" | |||
} | |||
|
|||
let t = React.jsx(Foo.component, {a: 1, b: "1"}) | |||
let t = React.jsxWithKey(Foo.component, {a: 1, b: "1"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why jsxWithKey
if the key is not passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/rescript-lang/rescript-react/blob/5e09771ae19b52bdb50061da15265b1093b6b61b/src/React.res#L51:L55
I think I should rename this function. 🤔
@@ -167,7 +167,10 @@ module V4A = { | |||
"div", | |||
{ | |||
children: ?ReactDOM.someElement( | |||
React.jsx(FancyInput.make, {ref: input, children: {React.string("Click to focus")}}), | |||
React.jsxWithKey( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why jsxWithKey if the key is not passed?
@@ -19,7 +19,7 @@ let c2 = React.createElement(A.make, {...p, x: "x"}) | |||
// let c0 = <A x="x" {...p0} {...p1} /> | |||
|
|||
// only spread props | |||
let c1 = React.jsx(A.make, p) | |||
let c1 = React.jsxWithKey(A.make, p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why jsxWithKey
is the key is not passed?
|
||
// reversed order | ||
let c2 = React.jsx(A.make, {...p, x: "x"}) | ||
let c2 = React.jsxWithKey(A.make, {...p, x: "x"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why jsxWithKey
is the key is not passed?
@cristianoc I think I'm done with this PR including:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
- Would you add an example with
<Foo ?key/>
- Update the changelog
cli/JSXV4.md
Outdated
|
||
<Comp x key=?Some("7")> | ||
// is transformed to | ||
React.createElement(Comp.make, Jsx.addKeyProp(~key=?Some("7"), {x: x})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it React.addKeyProp
as per rescript-lang/rescript-react#74?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I'll fix it.
Also, I was just wondering about the following: In addKeyProp(~key="42", {a: a, b: b /* and maybe many more props */}) we are creating the props object, it is not passed from outside. So why do we need to use |
Do you mean examples in the spec? or test? |
test |
Not sure I understand what you mean. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
@mattdamon108 does everything work with your project?
The mechanism used does 2 things:
Even though possible in principle, I'm not sure that both are possible at the same time currently, short of creating some new primitive with special runtime support. |
Oh maybe the question is only about imperatively adding the |
Yes, I meant that (props->Obj.magic)["key"] = key instead. |
Now I tested v3 and v4 classic & automatic, it works fine! |
Maybe this? rescript-lang/rescript-react@2f48356 |
It also works fine on tests. |
One impressive thing is that I don't need to change the existing codes between v3 and v4 classic and automatic, except for the Context provider component in my company code base which is a quite large project. |
We need to ensure that we do not mutate objects passed from user code. So if we do the mutation in Also, what happens in the case <A {...props} key /> ? Is props copied before being mutated or just passed through? |
Are there no tests for |
There's this too https://reactjs.org/docs/react-api.html#cloneelement |
This is a very good point. |
@cknitt Can you move this topic to rescript-react? rescript-lang/rescript-react#74 |
This PR fixes rescript-lang/rescript-react#73