Intento recibir de un archivo helperUtils, el valor que obtengo en una función. En esta función, primero llamo al backend para obtener información (esto funciona perfectamente), luego con este valor (es una matriz de datos) hago algunas cosas dentro de la función para devolver un nuevo valor.
Cuando llamo a esta función desde mi archivo .jsx e intento recibir el valor final, recibo Promise en mi consola cuando hago un archivo console.log.
función dentro de 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); } } } };en mi archivo.jsx:
lo intenté:
const getNewIdResponse = async () => { await getResponseId(`${getTopic}_${typeResponseTitle}_`); }; console.log(getNewIdResponse);y prueba:
const getNewIdResponse = getResponseId(`${getTopic}_${typeResponseTitle}_`); console.log(getNewIdResponse);todas las consolas imprimen: