Check this complete example.
import React, { Component } from "react";
import { View, TextInput } from "react-native";
export default class Example extends Component {
state = {
product: [
{
name: "item 1",
quantity: 10
},
{
name: "item 2",
quantity: 12
},
{
name: "item 3",
quantity: 14
}
]
};
onChangeText = ( item, text ) => {
let updateProducts = [...this.state.product]
let index = this.state.product.findIndex(obj => obj.name == item.name)
updateProducts[index].quantity = text;
this.setState({
product: updateProducts
})
}
render() {
return (
<View>
{this.state.product.map(item => (
<TextInput
style={{ height: 40, borderWidth: 1, margin: 5, width: "80%", padding: 5 }}
onChangeText={(text) => this.onChangeText(item, text)}
value={item.quantity}
/>
))}
</View>
);
}
}
Hope this helps you. Feel free for doubts.