I'm working with Picker component from React Native and I'm having some issues.
I'm trying to make a product registration page where each product has a catalog, so I'm using a Picker to show all catalogs that have been registered in the application. But, when I scroll the picker, it moves back to first item and when I press the button to registrate a product, I have the catalog field with undefined value. I'm using Formik for it.
Picker component:
<Picker style={{ height: 10, width: 325 }} value={this.state.selectedValue} mode="dropdown" itemStyle={{ backgroundColor: '#F6F6F6', color: 'black', height: 120, marginTop: 25, fontFamily: 'Ebrima', fontSize: 17, borderRadius: 5, borderColor: '#7e2f89', }} onValueChange={this.optionChanged}> {this.state.catalogs.map((member, key) => { return (<Picker.Item label={member.name} value={member.name} key={key} /> ); })}</Picker>
State and optionChanged:
state = { catalogs: [], selectedValue: '', }; optionChanged = value => { console.log(value); this.setState({ selectedValue: value}); };
Formik with initial values:
<Formik initialValues={{ name: '', description: '', costPrice: '', salePrice: '', catalog: '', amountStock: '', }} ...
How can I make it work properly?
Thank you in advance!