jshanson7 / react-native-swipeable

A powerful React Native swipe component.
MIT License
1.24k stars 273 forks source link

Warning when using RightButtons in FlatList - Each child in array should have unique key #58

Open RuairiOliver opened 6 years ago

RuairiOliver commented 6 years ago

Hi,

Has anyone used this component with a FlatList and experienced this issue with rightButtons?

"Each child in an array or iterator should have a unique "key" prop"

The component works great but the warning is irritating.

Thanks

suhabaobaid commented 6 years ago

I dont think that has to do with this component. When rendering a list you have to provide key attribute for each element. If you are using flatList, you will provide this function _keyExtractor = (item, index) => item.id; Check FLatList in react native docs

RuairiOliver commented 6 years ago

Thanks, yeah I have a unique key on my flat list items. It's definitely this component.

The problem I think is that this component just uses the array index as the key.

I think the issue is that in a list their will be multiple buttons with the key 1 and 2 because it just uses the button array index.

Example: FlatList Item with unique key containing 2 rightButtons with key of 1 and 2 FlatList Item with unique key containing 2 rightButtons with key of 1 and 2

I can change this component to let me pass a unique key through which gets rid of the warning anyway.

suhabaobaid commented 6 years ago

Can u plz post a snippet of your code ? As I am not having any warning while using the flatList

isaachinman commented 6 years ago

Also seeing this error:

screen shot 2018-04-05 at 18 29 59

Exact same use case, rendering Swipeable as a direct child of FlatList.

The solution is to manually provide keys to your button elements.