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

570
Views
How to get acces to the PromiseResult (react)

this is my code:

    const sendBoardId = async boardId => {
    let result;
    try {
        result = await axios.get(`${fetchConfig.prefix}/game/get_board_by_id`, {
            params: {
                boardId,
            },
        });
    } catch (e) {
        console.log(e);
    }
    console.log('board:', result.data);
    if (result.data == null || result.data.length == 0 || result.data == undefined) {
        const BoardData = [];
        return BoardData;
    }
    return result.data;
};

const Board = sendBoardId(1);

console.log('aaa', Board);

export { Board };

In the "aaa" console log I keep getting promise, and only in the promise result I got what I needed, I want to export the promise result and not all the promise it self. How should I do it?

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

0

To use Promise

const sendBoardId = async (boardId) =>
  new Promise(async (resolve, reject) => {
    let result;
    try {
      result = await axios.get(`${fetchConfig.prefix}/game/get_board_by_id`, {
        params: {
          boardId,
        },
      });
    } catch (e) {
      console.log(e);
      reject(e);
    }
    console.log("board:", result.data);
    if (
      result.data === null ||
      result.data.length === 0 ||
      result.data === undefined
    ) {
      resolve([]);
    }
    resolve(result.data);
  });

const Board = sendBoardId; // UseLess

console.log("aaa", Board);

export { Board }; // Better to direct export sendBoardId

And use:

import {Board} from "...........";

const xyz = async() =>{
const data = await Board(1);
}

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!