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
193 stars 90 forks source link

Value being returned from MultipleSelectList is not an array. #73

Open JCcastagne opened 1 year ago

JCcastagne commented 1 year ago

The value that you received from MultipleSelectList is not an array, it seems to be a value that wants to be set into an array.

Data:

const data = [
  "selection1 key": "selection1 value",
  "selection2 key": "selection2 value",
  "selection3 key": "selection3 value",
]

Example:

const [selection, setSelection] = useState()

<MultipleSelectList
  setSelected={value => setSelection(value)}
  data={data}
  search={true}
  placeholder='Make a selection'
  save='value'
/>

console.log(selection)
// ERROR: (_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__)(new Set([].concat((0,_babel_runtime_helpers_toConsumableArray__WEBPACK_…

The value seems unable to be deciphered. The only way around this was to do the following:

const [selection, setSelection] = useState([])

<MultipleSelectList
  setSelected={value => setSelection(value)}
  data={data}
  search={true}
  placeholder='Make a selection'
  save='value'
/>

console.log(selection)
// [selection1, selection2]

Once the value is saved into a state that is defined as an array on save, now I would then need to use a useEffect to set my data in my form. I could not simply just pass the value into my form directly.