Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
State not storing input data if value is given

I am trying to have an initial value in my input field before the user edits it. But when an initial value is given, it does erase when I try to remove it.

<Input
  type="text"
  placeholder={
  title === "" && fieldsFilled === false
  ? "This is a required field"
  : "Enter Title"
  }
  id="title"
  onChange={(e) => setTitle(e.target.value)}
  style={
  title === "" && fieldsFilled === false
  ? styles
  : null
  }
/>

Why is my state not updating when I change. What is wrong with the onChange?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Dont add initial value on placeholder use value to add it and initial value should come from hook as below

const [title, setTitle] = useState('initial value')

<Input
  type="text"
  placeholder={
  title === "" && fieldsFilled === false
  ? "This is a required field"
  : "Enter Title"
  }
  id="title"
  value = {title}
  onChange={(e) => setTitle(e.target.value)}
  style={
  title === "" && fieldsFilled === false
  ? styles
  : null
  }
/>

look on how i added the value = {title} on input tag, thats the key

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda