I am facing problems while displaying data fetched dynamically from an API. console log clearly shows that the promise has been fulfilled and the data has been successfully fetched but the data is somehow not getting displayed in the relevant container. I am using map method of arrays to dynamically display data using template strings. An inspection of the page also does not mentions any related errors in the code. what could be the problem?
const url = 'https://api.github.com/users/john-smilga/followers?per_page=100'
const fetchFollowers = async() => {
const response = await fetch(url);
const data = await response.json();
return data;
}
const getData = fetchFollowers();
const place = document.getElementById("container")
const display = () => {
let newFollowers = getData.map((item) => {
const {
avatar_url,
login,
html_url
} = item;
return `<article class="card">
<img src="${avatar_url}">
<h4> ${login}</h4>
<a href="${html_url}" class="btn"> view profile </a>
</article>`;
})
.join(" ");
place.innerHTML = newFollowers;
}
<div id="container"></div>
const getData = await fetchFollowers()fetchFollowersis an async function, if you want to return the data, you need to wait for it to complete.