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

328
Vistas
How to use setState function inside the function in functional component?

I am now working on a functional component

const [input_error, setInputError] = useState({
   harvest:false,
   stake:false,
   unstake:false,
   deposit:false,
   withdraw:false,    
   apy:false,
   period:false,
   feeaddress:false,
   harvestfee:false,
   unstakefee1:false,
   unstakefee2:false,
   unstakefee3:false,
   unstakefee4:false,
   unstakefee5:false,
});

function set_value(e) {
   let temp = JSON.parse(JSON.stringify(input_value));
   temp[e.target.name] = e.target.value;
   setInputValue(temp);
}

At this time, I cannot use set_value(e) to modify the state and render it correctly.

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

0

Because the state is object and you should use json to set the state. So JSON.parse(JSON.stringify(input_value));

to string and to json again.

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you are using react, I don't recommend doing this for immutability, use the spread operator like this:

setInputError({...input_error, [e.target.name]:e.target.value})
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