0

I wanted to add multiple pickers in React Native. I have a button when clicked a new picker should appear. I also want to store values of selected items of each picker in an array. I don't know how to make this possible. The callback of Picker onValueChange only sends item value and index in my case which can be same for 2 or more pickers. Please someone provide me a solution.

1 Answer 1

1

You can try to do something like this, in function handlePickerSelection you would be able to put value in array's element with index i

let pickers = [];
for ( let i = 0; i < numberOfPickers; i++) {
    pickers[i] = <Picker style={{height: 50, width: 100}} key={i} onValueChange={(value) => handlePickerSelection(value, i) }>
       <Picker.Item label="1" value={1}/>
       <Picker.Item label="2" value={2} />
   </Picker>
}
return (<View>{pickers}</View>)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.