I need to push items to my array, but when I console.log this array, it says 'undefined' for the specific value. I'm trying btw to fetch data from firebase storage.
How do I correctly add items to an Array?
My Code:
const [imagelinks, setImagelinks] = React.useState(['']);const myFunction = () =>{ await storage() .ref(`${_userid}`) .list() .then(result => { result.items.forEach(async ref => { await storage() .ref(ref.fullPath) .getDownloadURL() .then(url => { //get url setImagelinks([...imagelinks, url]); console.log('Links: '+ url); }); }); //there it says undefined when logging... console.log(imagelinks[0]) });}
What did I wrong?