React: how add key for fragment

Created on 14 Oct 2018  路  11Comments  路  Source: facebook/react

before i use

<Fragment key={index}>
now i use

<>

how add key this ?

< key={index}> has error

Most helpful comment

@uxitten Syntax works only for propless fragments. If you need to add key, just use React.Fragment. There's nothing wrong with it.

All 11 comments

@uxitten Syntax works only for propless fragments. If you need to add key, just use React.Fragment. There's nothing wrong with it.

@pd4d10 thanks i know i can use but my question is something else

@TrySound thanks but why?

@uxitten To not add complexity to the syntax.

@TrySound i thought <> is just alias <Fragment>

It's syntax extension which is transformed to React.Fragment, not alias

@TrySound thanks

Isn't this clean enough?
https://reactjs.org/docs/fragments.html
image
image

yes that's enough

Was this page helpful?
0 / 5 - 0 ratings