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

130
Visualizações
Promise pending issue in React

I try to receive from a helperUtils file, the value that i get in a function. In this function first i call to backend to get some information (this works perfect), then with this value (is an array of data) i do somethings inside te function to return a new value.

When i call this function from my .jsx file and try to receive the final value, i receive Promise in my console when i do a console.log.

function inside Helperutils.js

export const getResponseId = async (idStart) => { 
  const res = await getResponsIdApiNew(idStart);  
  if (res.length === 0) {    
    return (idStart + "1");
  } else {    
    let numbersArray = [];
    for (let j = 0; j < res.length; j++) {      
      if (res[j].substring(idStart.length, res[j].length)[0] !== "") {            
        numbersArray.push(Number(res[j].slice(idStart.length, res[j].length)));           
      }
    }
    if (numbersArray.length !== 0) {         
      const max = Math.max(...numbersArray);              
      let exist = false;
      for (let i = 1; i <= max; i++) {           
        if (!res.includes(idStart + i)) {          
          exist = true;
          idStart = idStart + i;
          console.log(idStart); //give me the value that i want
          break;
        }
      }
      if (exist) {
        console.log(idStart); //give me the value that i want
        return (idStart);
      } else {
        let number = max + 1;
        console.log(idStart + number)     
        return (idStart + number);
      }
    }
  }  
};

in my file.jsx:

i did try:

const getNewIdResponse = async () => {
    await getResponseId(`${getTopic}_${typeResponseTitle}_`);
  };
  console.log(getNewIdResponse);

and try:

const getNewIdResponse = getResponseId(`${getTopic}_${typeResponseTitle}_`);
console.log(getNewIdResponse);

all consoles print:

enter image description here

about 4 years ago · Juan Pablo Isaza
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