react-native-picker-dropdown icon indicating copy to clipboard operation
react-native-picker-dropdown copied to clipboard

Display label with Dynamic values in array.

Open Kirandeep7012 opened this issue 7 years ago • 1 comments

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 avatar Jan 31 '18 09:01 Kirandeep7012

@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" });

vikrantnegi avatar Mar 28 '18 05:03 vikrantnegi