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

223
Visualizações
Render Multiple images Supabase

I'm trying to download images from my superbase db and bucket. each post uploads multiple photos and gets its own folder id in which the images are stored. I then upload the image's pathNames to the DB so I can fetch the corresponding photos for the post on the next page. my problem is I'm having trouble rendering the correct photos to the correct post

how it works atm

  • 1.useEffect downloads all images from Db

  • 2.I need to match those img Ids with the IDS in the DB table to render photos §

the download fnc

const downloadImage = async (path, imgPath) => {
return await supabase.storage
  .from("public/job-photo")
  .download(`jobcomplete/${path}/${imgPath}`)
  .then(({ data, error }) => {
    if (error) throw error;
    return URL.createObjectURL(data);
  });

component

export default function Projects({ dataFetch, downloadImg, header, desc }) {
  const [urls, setUrls] = useState([]);
  // Fetch all URLS when the component mounts:
  console.log(urls);

  const postImgRender = () => {
    if (urls.some((e) => e.id === "q-kwhu8nkq")) {
      console.log(e, "Here");
      /* vendors contains the element we're looking for */
    }
  };

  useEffect(() => {
    if (!dataFetch) return;
    dataFetch.forEach((item, i) => {
      for (let i = 0; i < item.imgPath.length; i++) {
        const newImage = item.imgPath[i];
        downloadImg(item.genid, newImage).then((url) => {
          let imgObj = {
            id: item.genid,
            imgPaths: url,
          };
          setUrls((prevState) => [...prevState, imgObj]);
        });
      }
    });
  }, []);

  return ( ect.....

JSX

{dataFetch ? (
    <div className="mt-12 max-w-lg mx-auto grid gap-5 lg:grid-cols-3 lg:max-w-none">
      {dataFetch.map((item, i) => (
        <div
          key={item.genid}
          className="flex flex-col rounded-lg shadow-lg overflow-hidden"
        >
          <div className="flex-shrink-0">
            {urls.map((url, i) => {
              if (Object.keys(url.id) === item.genid);
              return <img src={url.imgPaths} />;
            })}
          </div>

Trying to work out if this would be the correct approach maybe get the keys im not sure?

 const postImgRender = () => {
    if (urls.some((e) => e.id === "q-kwhu8nkq")) {
      console.log(e, "Here");
      /* vendors contains the element we're looking for */
    }
  };

URLS ARR DATA

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

0

solve it I belive

{urls.map((url, i) => {
                      if (url.id === item.genid) {
                        console.log("here");
                        return <img src={url.imgPaths} />;
                      } else {
                        return null;
                      }
                    })}
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