Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

327
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda