danish1658 / react-native-dropdown-select-list

☝️ React Native Select List Equivalent to Html's Select with options"
https://www.npmjs.com/package/react-native-dropdown-select-list
MIT License
200 stars 89 forks source link

How to setSelected = key #60

Closed conorwaltersUno closed 1 year ago

conorwaltersUno commented 1 year ago

Hi,

I have been having some troubles implementing the setSelected method to save the selected key. All I can manage to do is save the value.

My data array looks like the following:

[{ key: "1", value: "name"}, { key: "2", value: "name2"}]
<SelectList
          setSelected={(key) => {
            console.log(key);
            setSelectedBoatId(key);
          }}
          data={data}
          save="value"
          defaultOption={data[0]}
        />

Here I want the setSelectedBoatId to take in the number held in the object key but all I seem to be able to get is the value. If anyone can help out would be greatly appreciated! 🚀

conorwaltersUno commented 1 year ago

Nevermind...... was being stupid and didnt realise the save="value" controls what is being passed into the setSelected function.... 😮‍💨 🔫