I have the following code:
let allurl = []
const [toReadurl, setToReadurl] = useState([])
useEffect(() => {
const listRef = sRef(storage, paramKey)
// Find all the prefixes and items.
listAll(listRef)
.then((res) => {
res.prefixes.forEach((folderRef) => {
// All the prefixes under listRef.
// You may call listAll() recursively on them.
});
res.items.forEach((itemRef) => {
// All the items under listRef.
//console.log(itemRef)
getDownloadURL(itemRef).then((url =>{
//console.log(url)
allurl.push(url)
setToReadurl(allurl)
}))
});
}).catch((error) => {
// Uh-oh, an error occurred!
console.log(error)
});
}, [])
console.log(toReadurl)
This piece of code above is to get the download url from the items that are stored in firebase storage. The above works and I am able to read 4 different URL out but when I tried to store it in toReadurl
, it only get to store 2 url instead of 4 url. How do I ensure toReadurl
gets to store all 4 properly.
Another issue is where I tried to display it out
<Text>{toReadurl}</Text>
It display the first url only
I tried
<Text>{toReadurl[0]}</Text>
<Text>{toReadurl[1]}</Text>
It display only the last item in the array for both. What do I do to display it out properly?