How to change my input value on my TextInput React native

Viewed 62

I have my .map and i wanna change the value of my values inside the .map.

On my textInput i used the method "onChangeText" like that :

 {CRMData.rows.map((element, key) => {
          return (
            <View key={key}>
              <View
                style={{
                  flexDirection: "column",
                  justifyContent: "center",
                  alignItems: "center",
                }}>
                <View>
                  <Text style={styles.itemRecord}>{element.Record}</Text>
                </View>
                <View>
                  <TextInput
                    style={{
                      borderWidth: 1,
                      width: 180,
                      height: 30,
                      marginBottom: 20,
                      borderRadius: 10,
                    }}
                    placeholderTextColor="#E8E2E2"
                    value={element.Value}
                    onChangeText={(text, event) => {
                      const newValues = [...values]; // Use this if you map on an array
                      newValues.push(text);
                      setValues(newValues);
                    }}
                  />
                </View>

my problem is i can't send my onChange because after writing one thing i loose the focus and my text disapeared.

How i can change that ?

1 Answers

Try below code onChangeText

 onChangeText={text => {
      
     values[rowData.index] = {... values[rowData.index], value: text};
     setValues(values);
      }
    }

here values is your state variable which you store array data.

Related