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

118
Views
Clicking twice to see the value - UseState - UseEffect React using Function Component

I'm having a newbie problem, I really read all the documentations about it, and have seen all the stackoverflow about this issue, and I still can't get it right.

I need to get a value from a const variable, that I'm seeting without clicking twice, I tried a million things and still can't make this happen.

    const [GetCode,setGetCode] = useState("");
     const GetCodeMI = () =>{
    Axios.get('http://localhost:3001/GetMICode',{ }).then((response)=>{

            // console.log(response.data[0].ZZE_CODIGO);
             setGetCode(response.data);
         
        });
 }   
  const  InsertInternalMov = () => {
    GetCodeMi2().then(()=>{
        console.log(GetCode[0]);
      })
  }

In this scenario the first time that I click on the function the value of GetCode it's undefined the second time it shows correclty. I need to get the value the first time I click, My head it still wraping around how react works.

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

0

  1. if you want to set value immediately, you can try to use React.useRef()
  2. setGetCode is asynchronous function
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!