Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

using useDatabaseListData and useStorageDownloadURL to display images but the loop only ran the first time #504

Unanswered
grojas123 asked this question in Q&A
Discussion options

Hi, Reacfire team I need a guide on why this is happening and how to fix this .
I am using two hooks of Reactfire useDatabaseListData to get the URLs of the images from the real-time database and useStorageDownloadURL to get and display the images.
For some reason the "for loop" ran only the first time (even if I checked the imagesarray.length in the last tried got the final list of images).

function Displayphotos(photosmetada) 
 {
 const urlminimalblankimage="https://firebasestorage.googleapis.com/xxxxxxxxxxxxxxxxx..."
 const minimalblankobject=[{"author":"","id":"07355838-54d7-436e-9bcc-6688467c2990","timestamp":"","url":urlminimalblankimage}];
 if (typeof (photosmetada.photosmetada.user) !== 'undefined') 
 {
 var gameid = photosmetada.photosmetada.gameid;
 }
 var database = useDatabase();
 var querypath = '/photos/' + gameid;
 const photosRef = refdatabase(database, querypath);
 const objectlistofimages = useDatabaseListData(photosRef);
 var imagesarray=objectlistofimages.data;
if (typeof (imagesarray) === 'undefined'){
 imagesarray=minimalblankobject;
}
 const photoRefoneimageblank = ref(storage,urlminimalblankimage);
 var imagesarraylength=imagesarray.length;
 
 for (let i=0; i < imagesarraylength;i++) 
 {
 console.log(i);
 console.log(imagesarraylength);
 var urlimageref=imagesarray[i].url;
 var photoRefoneimage = ref(storage,urlimageref);
 var { status, data: imageURL } = useStorageDownloadURL((typeof (imagesarray) !== 'undefined') ? photoRefoneimage:photoRefoneimageblank);
 if (status === 'loading') 
 
 return <span>loading...</span>;
 return <img src={imageURL} alt="game NSYL" />
 
 }
 }

Pls any guide.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /