score:-3

useEffect(() => {
  getImage();
}, []); // Calling getImage function to fetch data

const [items, set] = useState([]);

async function getImage() {
  try {
    const response = await axios.get("https://picsum.photos/v2/list");
    let image = response.data;

    for (var i in image) {
      let x = "https://picsum.photos/id/";
      let y = image[i].id;
      let v = image[i].width;
      image[i].author = `${x}${y}/${v}/${image[i].height}`;
      image[i].height = Math.floor(Math.random() * 650) + 300;
      let z = image[i].height;

      image[i].download_url = `url(${x}${y}/${v}/${z})`;
    }
    set(image); // setting state after fetching data
  } catch (error) {
    console.error(error);
  }
}

score:10

useEffect(() => {
  // executed only once
}, [])

Related Query

More Query from same tag