happiness (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) happiness

【react】Each child in a list should have a unique "key" prop. でIn Fragmentのときの修正

エラー内容

Warning: Each child in a list should have a unique "key" prop. 

<中略>
In Fragment

In Fragmentを勝手にGraphQLのFragmentと勘違いしてしまいハマってしまった。

直し方

before

{categories.map((category) => (
<>
</>
)}

after

<>ではなく、React.Fragmentと明記する

{categories.map((category) => (
<React.Fragment key={category.id}>
</React.Fracment>
)}

参考

javascript - Each child in an array or iterator should have a unique "key" prop. in react js? - Stack Overflow