score:300

Accepted answer

To add a key to a fragment you need to use full Fragment syntax:

<React.Fragment key={your key}>
...
</React.Fragment>

See docs here https://reactjs.org/docs/fragments.html#keyed-fragments

score:1

You can also use this way to auto assign key to your component list

React.Children.toArray(someData.map(data=><div>{data.name}</div>))

score:6

Yes, you can add a key in the below form Fragment which is not possible in the shorter version of Fragments(i.e, <></>)

<Fragment key={your key}></Fragment>

For Reference


Related Query

More Query from same tag