- Instant help with your JavaScript coding problems

Add key prop to React fragment

Question:
How to add key prop to React fragment?
Answer:
<React.Fragment key={id}>
...
</React.Fragment>
Description:

You can create React fragments with the short syntax: <>...</> However, with this syntax, you can not add key props. To add a key prop, simply use the normal syntax <React.Fragment key={myKey}>

 

Share "How to add key prop to React fragment?"