Hi everyone,
I’ve been working on a personal portfolio, and I would like to show random photos on my Flickr account.
So here its the whole of this section of my react.
import './Flickr.scss';
import React, { useEffect } from 'react';
export function Flickr(props) {
function Myphotos() {
let img1 = { photoid: '', photosecret: '' };
let urlflickr = `https://www.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=3e7dff85a13f1e234c02931ac56a4cd4&user_id=69387047%40N04&per_page=43&page=1&format=json&nojsoncallback=1`;
fetch(urlflickr)
.catch((error) => console.error('Error:', error))
.then((response) => response.json())
.catch((error) => console.error('Error:', error))
.then((response) => {
let random1 = Math.floor(Math.random() * response.photos.photo.length);
img1.photoid = response.photos.photo[random1].id;
img1.photosecret = response.photos.photo[random1].secret;
if (img1) {
let urlimg1 = `https://live.staticflickr.com/65535/${img1.photoid}_${img1.photosecret}_b.jpg`;
document.getElementById('uno').style.backgroundImage = `url(${urlimg1})`;
}
});
setTimeout(Myphotos, 15000);
}
function Followmeflickr() {}
return (
<div className="flickr">
<h2>FLICKR PHOTOS</h2>
<div class="photos">
<div className="photo" id="uno" />
</div>
</div>
<script>{Myphotos()}</script>
</div>
);
}
export default Flickr;
So, I can see one first photo that is changed really fast and after stay 15seconds until I see two photos again.
I’ve been working on it, but couldn’t find the answer.
I tried to have it like onLoad={Myphotos}
I would like to know if someone more had this problem. Thanks