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

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

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 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