so I am trying to get into react but it gives me a lot of headaches... The current one: I created a State Hook which seems to be the react-version of a classical array.
const [downloadLinks, setDownloadLinks] = useState([]);
Then I used an async function to fetch data:
const getFileList = async() =>{
const fileList = await list(
listRef, {maxResults: 10}
)
.then(
(res) => {
res.items.forEach((item) => {
// We get the download link for each
getDownloadURL(ref(storage, item))
.then((url) => {
// log this link
console.log("getFileList-URL: " + url)
// Add it to the array
setDownloadLinks(old => [...old, url])
console.log("Test the length: " + downloadLinks.length)
})
});
getFileDescriptions();
}
);
};
And here we see the issue: I looked up several ways to append elements to a state in react but it all comes down to this. And the state doesnt change at all. The length stays the same, there are no more elements inside. I even log "url" to be sure that it is not null. But nothing works.
Any advice?