English 中文(简体)
消防基地储存图《URLs》正在ole上锁,但没有在网页上更新。
原标题:Firebase Storage Image URLs are being console logged onclick but not updated on page with ReactJS

I have a React project where i get photo URLs from firebase storage (getPhotoArray function) I have the correct urls being console logged when i click the button, but it doesnt show on my page.

I have multiple photos in the firebase storage folder and i am getting the right amount and right photos console logged in the array(in getPhotoArray function)


export const getPhotoArray = async (selectedDonation, setPhotos) => {
  const listRef = ref(storage,  /Images/ +selectedDonation.id);
  const images = []
  listAll(listRef)
    .then((res) => {
      if (res.items.length > 0) {
        res.items.forEach((itemRef) => {
          // Get the download URL
          getDownloadURL(ref(storage, itemRef.fullPath))
          .then((url) => {
            images.push(url)
          })
          .catch((error) => {
          });
        });
        setPhotos(images)
        console.log(images)
      }else {
        toast.info( No Photos Found, Please Try Again Later )
      }
    }).catch((error) => {

    });   
}
import React, {useEffect, useMemo, useState} from  react 
import  ./donation_information.css 
import {getReceiptURL, getPhotoArray} from  ../../API/FirestoreAPI  

export default function DonationInformation({ selectedDonation, selectedDonationSteps }) {
  const [Photos, setPhotos] = useState([]);
 
  const getPhotos = () => {
    getPhotoArray(selectedDonation, setPhotos)
  }

 useEffect(() => {
  setURL(  )
  setPhotos([])
 }, [selectedDonation]);

  return (
    <div className= donationInformation >
        <div className= download-photos >
          <button onClick={getPhotos}>Show Photos</button>
          {
            useMemo(() => {
              Photos.map((photo) => {
                return <img src="photo" key={photo} alt="" />
              })
            }, [Photos])
          }
        </div>
        </div>
    </div>
  )
}

I have tried wrapping the Photos.map with useEffect, thats the only thing i could think of

问题回答

You need to add curly braces {} to your <img src attribute instead of double quotes as src is set to a variable photo. Also set a width and height

Your current code :

return <img src=“photo” key={photo} alt=”/>

needs to be updated to

return <img src={photo} key={photo} alt="" width="500" height="600"/>





相关问题
How to use one react app into another react app?

I have two react apps, parent app and child app. and child app have an hash router. I have build the child app using npm run build, It creates build folder. That build folder moved into inside the ...

how to get selected value in Ant Design

I want to print the selected value, and below is my option list: const vesselName = [ { value: 0 , label: ALBIDDA , }, { value: 1 , label: ALRUMEILA , }, { value: 2 ,...

How to add a <br> tag in reactjs between two strings?

I am using react. I want to add a line break <br> between strings No results and Please try another search term. . I have tried No results.<br>Please try another search term. but ...

热门标签