react-native-picker-dropdown
react-native-picker-dropdown copied to clipboard
Display label with Dynamic values in array.
i have my picker code as follows: <Picker style={styles.picker} prompt="Choose your Class" selectedValue={this.state.language} textStyle={styles.pickerText} onValueChange={(itemValue, itemIndex) => this.setState({ language: itemValue })} >
{classList.map((item, index) => {
return (< Picker.Item label={item.ClassName} value={item.ID} key={index} />);
})}
</Picker>
Here in the above i want that my picker opens up with a default label like "Please Select Value".Instead of showing up the first value in the array. Please Suggest your valuable suggestions. thanx in advance.
@Kirandeep7012 I had the same issue.
What you can do is here is that you can push "Please select a value" inside your array as the first item, before mapping through it. The picker will show it as the first default item. You can use "unshift" array operator for this.
classList.unshift({ id: "0", name: "Select option" });