Skip to content
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

JSX: weird error message when using "children" as prop #7046

Open
cknitt opened this issue Sep 22, 2024 · 3 comments
Open

JSX: weird error message when using "children" as prop #7046

cknitt opened this issue Sep 22, 2024 · 3 comments
Assignees
Milestone

Comments

@cknitt
Copy link
Member

cknitt commented Sep 22, 2024

When one has a React component accepting children, e.g.

module A = {
  @react.component
  let make = (~children) => <div> {children} </div>
}

and, instead of passing the children like this:

let _ = <A> {React.string("test")} </A>

one accidentally passes them as a prop:

let _ = <A children={React.string("test")} />

then one gets the error message

JSX: somehow there's more than one `children` label

which feels weird as children were actually passed only once.

@cknitt cknitt added this to the v12 milestone Sep 22, 2024
@zth
Copy link
Collaborator

zth commented Sep 22, 2024

What should it say? "Children should be passed as JSX, not a prop"?

@mununki
Copy link
Member

mununki commented Sep 23, 2024

let _ = <A children={React.string("test")} />

I not certainly sure, is it allowed in the React usage? As far as I know it is not allowed.

@cknitt
Copy link
Member Author

cknitt commented Sep 23, 2024

I not certainly sure, is it allowed in the React usage? As far as I know it is not allowed.

It seems to work in babel.

I am not saying that we should allow it in ReScript, just that the error message is confusing in this case.

What should it say? "Children should be passed as JSX, not a prop"?

"Children must be passed as JSX content, not as a prop. Ensure that child elements are placed between the opening and closing tags of the component."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants