moroshko / react-autowhatever

Accessible rendering layer for Autosuggest and Autocomplete components

Home Page:http://react-autowhatever.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set "key" on item

baktun14 opened this issue · comments

Hi, I am using the react-autosuggest and I saw in the react warnings

Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `Item`. See https://fb.me/react-warning-keys for more information.
    in b (created by Item)
    in Item (created by ItemsList)
    in ul (created by ItemsList)
    in ItemsList (created by Autowhatever)

I think you should just put the key of the itemList map index instead of the optional theme..
Here

<Item
                **key={itemIndex}**
                {...allItemProps}
                sectionIndex={sectionIndex}
                itemIndex={itemIndex}
                item={item}
                renderItem={renderItem}
                renderItemData={renderItemData} />

Sorry I was too in a rush to make a PR...

You are pointing to the render method of ItemsList, while the warning points to the render method of Item.

Could you create a Codepen that demonstrates the issue?

Ah! You're right, it's my code's fault. I was using the renderSuggestion method from react-autosuggest to render custom suggestions where I iterate over the string to put part of the string in bold matching the searched characters from the tags input.
Thanks anyways! Cheers