Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

326
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!