Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

74
Vistas
Why the input name is not changing its value?

I'm trying to edit the user profile data, and when I change the name in the input field, it won't change, it keeps the name that the user has.

 const [nameInput, setNameInput] = useState('');


  const editUserData = () => {
    const userParams = {
      phone: phone,
      fullName: nameInput,
      gender: value,
      birthdate: date,
    };
    axios
      .put('url', userParams)
      .then((response) => {
        console.log('response', response.data);
      })
      .catch((error) => {
        console.log(error.message);
      });
  };

  <TextInput
      style={styles.nameInputStyle}
      onChangeText={(event) => setNameInput(event)}
      value={nameInput}
      keyboardType="email-address"
      returnKeyType="done"
      onEndEditing={(e) => handleValidName(e.nativeEvent.text)}
      autoCapitalize="sentences"
   />

How can I change the value name in the input field?

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to set it to event.target.value, not event:

<TextInput
      style={styles.nameInputStyle}
      onChangeText={(event) => setNameInput(event.target.value)}
      value={nameInput}
      keyboardType="email-address"
      returnKeyType="done"
      onEndEditing={(e) => handleValidName(e.nativeEvent.text)}
      autoCapitalize="sentences"
/>

EDIT

event.target.value won't work. Use this instead:

<TextInput
      style={styles.nameInputStyle}
      onChangeText={setNameInput}
      value={nameInput}
      keyboardType="email-address"
      returnKeyType="done"
      onEndEditing={(e) => handleValidName(e.nativeEvent.text)}
      autoCapitalize="sentences"
/>
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos