AdelRedaa97 / react-native-select-dropdown

react-native-select-dropdown is a highly customized dropdown | select | picker | menu for react native that works for andriod and iOS platforms.
MIT License
314 stars 134 forks source link

I need objects with label and value #140

Closed mfernandezgarcia closed 1 year ago

mfernandezgarcia commented 1 year ago

I am trying to pass the "data" prop

data={zones.map(zone => ({ value: zone.id, label: zone.name, }))}

But React Native is given me the following error: " ERROR Error: Objects are not valid as a React child (found: object with keys {value, label}). If you meant to render a collection of children, use an array instead."

I want to show the user a value but then I need to find the object given its id, is it possible?

raychanks commented 1 year ago

Are you trying to show the text in label for each row when the dropdown is opened and when it's selected? If so, try the following to see whether it solves your issue.

<SelectDropdown
  data={zones.map(zone => ({ value: zone.id, label: zone.name }))}
  buttonTextAfterSelection={(selectedItem) => selectedItem.label}
  rowTextForSelection={(item) => item.label}
  // other props
/>
mfernandezgarcia commented 1 year ago

Are you trying to show the text in label for each row when the dropdown is opened and when it's selected? If so, try the following to see whether it solves your issue.

<SelectDropdown
  data={zones.map(zone => ({ value: zone.id, label: zone.name }))}
  buttonTextAfterSelection={(selectedItem) => selectedItem.label}
  rowTextForSelection={(item) => item.label}
  // other props
/>

Yass, that's exactly what solved the problem!! Thanks