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

"Shorthand fragment syntax does support providing keys" when it does not #2365

Closed
JonnyBurger opened this issue Jul 31, 2019 · 5 comments · Fixed by #2367
Closed

"Shorthand fragment syntax does support providing keys" when it does not #2365

JonnyBurger opened this issue Jul 31, 2019 · 5 comments · Fixed by #2367

Comments

@JonnyBurger
Copy link

{[0, 1, 2, 3].map(key => {
   <>
       <div>{key}</div>
   </>
})}

error Missing "key" prop for element in iterator. Shorthand fragment syntax does support providing keys

It says the shorthand fragment syntax does support keys, but I think it does not support it, or does it?

Asking if this is a typo.

@ljharb
Copy link
Member

ljharb commented Jul 31, 2019

It does, afaik - the purpose of fragment syntax is to avoid the need for a key on the children, not on the fragment itself.

@JonnyBurger
Copy link
Author

Ok, then how do we use it?

< key={1}></>

does not work. To clarify my question, the shorthand fragment syntax in my understanding is <></> while the regular syntax is <Fragment></Fragment>.

@ljharb
Copy link
Member

ljharb commented Jul 31, 2019

hmm, that is a good point. #2316 added this; cc @kaykayehnn - it does seem like perhaps the error message has a typo, because there’s no tests with shorthand syntax and a key.

@kaykayehnn
Copy link
Contributor

Whoops, this is a typo - shorthand fragment syntax does not support providing keys. Passing keys to fragments is only supported with the regular syntax: <Fragment key={1}></Fragment>

I'll make a PR to fix this and update the docs.

@JonnyBurger
Copy link
Author

Wonderful! Thanks a lot for your effort - This plugin is mindblowing! 💙

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

Successfully merging a pull request may close this issue.

3 participants