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

182
Views
react js can't update button status using useState

I want to set pending status in my button using useState when sumitting forms but I don't know where I am doing mistake:

here is my code:

const [is_pending, setIs_pending] = useState(false);
 const SubmitContact = async (e)=>{
        e.preventDefault()
        setIs_pending = true;
        let url = "http://localhost:8000/my-api/"
        const res = await axios.post(url,{
          contact_name:contact_name,contact_email:contact_email,contact_body:contact_body
        }).then((res)=>{
            console.log(res)
            setIs_pending = false;
           
        });


 <form onSubmit={SubmitContact}>
            ...my others html code
         { !is_pending && <button className='btn btn-primary'>Send Message</button> }
         { is_pending && <button type='submit' className='btn btn-primary' disabled>Sending Message....</button> }
 </form>

I set { is_pending && <button type='submit' className='btn btn-primary' disabled>Sending Message....</button> } when forms will be procession but I don't know why this status not showing when submitting forms.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

setIs_pending is a function, and you can't set value using =!

To set value correctly you need to pass the value as param of setIs_pending, like:

YOUR_CODE....

setIs_pending(true);

YOUR_CODE....

You can read more here: https://pt-br.reactjs.org/docs/hooks-intro.html

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!