0

I have result from DB with object below. I can only print it to console. How do I eg. use it in formatted console output such as

console.log(`Hello ${name} (${age}) from ${city}`);

Do I save it into array locally and the use it in react component? What is the best practice?

Output from code below:

{ name: 'alice', city: 'New York', age: 34 }

Promise:

 Promise.all(promises).then(([res1, res2]) => {
    getProfile(res1, res2).then(console.log);
  })
pilchard
  • 12,414
  • 5
  • 11
  • 23
Azm
  • 81
  • 1
  • 2
  • 8
  • 1
    So your question is how to print that object as a "Hello..." message? Then your question doesn't relate to `Promise.all`, really. – trincot Mar 29 '23 at 08:54
  • 1
    ``getProfile(res1, res2).then(({ name, city, age }) => console.log(`Hello ${name} (${age}) from ${city}`))`` – Kapobajza Mar 29 '23 at 08:55
  • 1
    Are you fetching within a component? Possibly look at [How to call an async function inside a UseEffect() in React?](https://stackoverflow.com/questions/56838392/how-to-call-an-async-function-inside-a-useeffect-in-react) – pilchard Mar 29 '23 at 09:01
  • 1
    @pilchard yes that is pattern Im looking for. thank you – Azm Mar 29 '23 at 09:07

0 Answers0