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

250
Vistas
Nextjs: onChange input not change value on self

This is my code:

const [defaultBuy, setDefaultBuy] = useState({
    data: '',
    price: 0
})

const changeBuyPrice = (e: any) => {
    let value = e.target.value
    if (value > 1000) {
        value = 9000
    }
    console.log(value)
    setDefaultBuy({...defaultBuy, price: value})
}

And this is render:

<input defaultValue={defaultBuy.price} name="" type="text" onChange={(e) => changeBuyPrice(e)} />

If I put number larger than 1000 in input, console.log(value) show me 9000.

But <input> tag not show 9000.

I want to change <input> value also

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

0

If you want the input to reflect the value in the state then you need to make it a controlled component.

Assign the value in the state to the value prop instead of the defaultValue prop.

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