Freelancer, Full-stack developer (React.js / React Native / TypeScript / Node.js). I've come to specialize in developing Dashboards, Administrative Panels, CRM systems, and similar apps.
But what if i had to take the return value of Promise to use as data to render ?
my case is that : I have to query database to get the link for 'src' attribute ? I use mongoosejs
Hope you can explain . Thank You
const address = fetch("jsonplaceholder.typicode.com/users/1")
.then((response) => response.json())
.then((user) => {
return user.address;
});
const printAddress = async () => {
const a = await address;
console.log(a);
};
let d = printAddress();
console.log(d); <-------- how do I do this? this still returns a Promise { }
I want to access return value from printAddress()
That's the whole point! You can use the return value from the Promise object ONLY in a async function.
You should do all the stuff that you'd like to do with the return result in a printAddress() async function.
But what if i had to take the return value of Promise to use as data to render ?
my case is that : I have to query database to get the link for 'src' attribute ? I use mongoosejs
Hope you can explain . Thank You
i find a new solution
the best way to use a promise ...... use a promise inside a promise ...it will work