Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React Native: Pushing items to State Array not working

$
0
0

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?


Viewing all articles
Browse latest Browse all 6287

Trending Articles