I know that, in React, you can't add a key to an empty fragment:
// will result in an error
< key={'foo'} >
{...}
</>
Instead, you need to use React.Fragment
:
// works fine
<React.Fragment key="foo">
{...}
</React.Fragment>
The React documentation notes this, but it doesn't explain why, and I'm curious. Is it a limitation in JSX? Or is it a design decision that React made for some reason?
Edit: I found this post. It sounds like Fragment
came first, then <>
followed (and was upstreamed to JSX). But why didn't they make it so it could be parameterized? Just curious on the context of the decision and if there's an underlying reason, since I don't understand JSX all that well.