react-native-dropdown-picker: Unable to select multiple values
im having problems when I want to select multiple items. When I select one option they throw me this error: TypeError: Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a Symbol.iterator method.
Anyone know how to solved this problem??
im using the version: “react-native-dropdown-picker”: “^5.1.21” here is what im doing:
export default class Example extends React.Component {
constructor(props) {
super(props);
this.state = {
openCurrencyDropDown: false,
data: [
{ label: 'Op1', value: "Op1" },
{ label: 'Op2', value: "Op2" },
{ label: 'Op3', value: "Op3" },
{ label: 'Op4', value: "Op4" },
{ label: 'Op5', value: "Op5" },
{ label: 'Op6', value: "Op6" },
],
value: [],
}
this.setValue = this.setValue.bind(this);
}
setValue(callback) {
this.setState(state => ({
value: callback(state.value)
}));
}
render() {
<DropDownPicker
listMode={'MODAL'}
multiple={true}
min={0}
max={5}
open={this.state.openCurrencyDropDown}
setOpen={this.setOpenCurrencyDropDown}
setValue={this.setValue}
items={this.state.data}
defaultValue={this.state.value}
/>
}
}
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 18 (6 by maintainers)
@kjoonas1 Note that your state variable (value) must be an array
[]
Follow the official example: https://hossein-zare.github.io/react-native-dropdown-picker-website/docs/usage/#multiple-items
Hello @hossein-zare , @kjoonas1, @mikehardy Need some help here, the selected items are not getting displayed in class based component. I debugged and found multiple values are actually getting selected but not getting display
Please check the below link for live example: https://snack.expo.dev/@amitvarshney/1e644a
Please check the below example
@kjoonas1 Interesting!
setValue
’s callback always gets the current value, Thevalue
variable isn’tundefined
while thevalue
param in the callback isundefined
.The
value
doesn’t change until you press an item, There’s something wrong on your side i believe.I encourage you to try firing the
setValue
in auseEffect
:Don’t forget to restart your app after the changes.