Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

254
Visualizações
Is there a way to prevent getting photos randomly on Firebase Storage?

I have some folders on Firebase Storage. Every folder includes 1_org_zoom.jpg file. I can get those photos, but not in the right array order. I want to get those photos in an order like the photo below, but photos are shown randomly. I tried for loop and forEach, but didn't work. Is there any way to get these photos in an order?

  useEffect(() => {
  /* for(let i = 0; i<products.length; i++){
     const imgRef = ref(storage, imgFolderRef[i]);
     console.log(imgRef);
     getDownloadURL(imgRef)
       .then((url) => {
         console.log(url);
       })
   }
*/
   imgFolderRef.forEach((imgFolder) => {
     console.log(imgFolder);
     getDownloadURL(ref(storage, imgFolder))
       .then((url) => {
           setExArr((oldArr) => [...oldArr, url])
       })
   })
  
  }, [products]);

Array name is imgFolderRef.

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The whole point of asynchronous functions is not to block the execution of the script so that several operations can run concurrently.
In your case getDownloadURL and setExArr are asynchronous, as a consequence you have no guaranty concerning the ordering of the images. What you can do is to explicitly sort the array:

setExArr((oldArr) => [...oldArr, url].sort())
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda