'How i can change just one value on my object and keep my default value for the other values?
i wanna do an update function , all my data is dynamic and sometimes i would like update just one value.
I set up my values , then i used the props default values to keep my value inside my input but when i wanna change just one input , my object update only the value i changed on my onChangeText.
How i can say if i don't write a new value keep my default value inside my object value ?
{CRMData.columns.map((element, key) => {
return (
<View key={key}>
{element.Header === "Update" ? null : (
<View>
// i set up the names of my differents input
<Text>{element.Header}</Text>
// i keep my default value thanks to the props default value
<TextInput
defaultValue={
modalBusiness
? CRMData.rows[indexDeal][element.Header]
: ""
}
// i change my text by my current text
onChangeText={(text) => {
console.log("text", text);
setValues((prevState) => ({
...prevState,
[element.Header]: text,
}));
console.log("value", values);
}}
style={styles.input}
placeholderTextColor="#E8E2E2"
placeholder="prenom"
/>
</View>
)}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
