hossein-zare / react-native-dropdown-picker

A single / multiple, categorizable, customizable, localizable and searchable item picker (drop-down) component for react native which supports both Android & iOS.
https://hossein-zare.github.io/react-native-dropdown-picker-website/
MIT License
971 stars 295 forks source link

Getting the `index` of `renderListItem` #589

Open vozaldi opened 1 year ago

vozaldi commented 1 year ago

Hello,

I have successfully rendering custom ListItem in my dropdown picker, however I couldn't find a way to get the index of each item. How can I achieve something like [].map((props, index) => ...) by using renderListItem prop?

<DropDownPicker
  items={[{ label: 'First', value: 1 }, { label: 'Second', value: 2 }]}
  ...
  renderListItem={(props) => (
    <Pressable>
      <Text>{`_(index + 1)_. ${props.label}`}</Text>
    </Pressable>
  )}
/>

Wanted result in the list:

  1. First
  2. Second

Thank you for the help!