DEV Community

Discussion on: Javascript: How to access the return value of a Promise object

Collapse
 
onlykingkd profile image
Kaustubh Dwivedi

const address = fetch("jsonplaceholder.typicode.com/users/1")
.then((response) => response.json())
.then((user) => {
return user.address;
});

const printAddress = async () => {
const a = await address;
return a;
};

*Console.log(a) inside printAddress is working fine but :
Now I need to call this printAddress inside the return of a react Component thats why I am returning 'a' from printAdress, there it is showing promise pending. Is there any way to solve this ? *

Collapse
 
ramonak profile image
Katsiaryna (Kate) Lupachova

could you provide a piece of code of your react component? it would be easier to understand and will try to help.