I have the following code:
const getFromFirebase = () => {
//1.
let storageRef = storage.ref(`${user1}/${currentItem.id}`);
//2.
storageRef.listAll().then(function (res) {
//3.
res.items.forEach((imageRef) => {
imageRef.getDownloadURL().then((url) => {
//4.
if (allImages.indexOf(url) === -1) {
setImages((allImages) => [...allImages, ({Test : url, Test2 : imageRef.name})]);
}
});
});
})
.catch(function (error) {
console.log(error);
});
};
I am calling this function on a tab onclick - it works in that it shows the documents but if I click the tab again it simply repeats itself - how do I run a check that if all documents are showing already to not double up?
work with callback function, you did not enter an empty array.