Hi I’m using Marvel API and I have this:
export default function App() {
const [characters, setCharacters] = React.useState([]);
const items = characters.map((character, idx) => (
<LazyLoad key={idx} once throttle={2000} height={"300"}>
<Character
img={
character.thumbnail.path +
"/standard_xlarge." +
character.thumbnail.extension
}
name={character.name}
/>
</LazyLoad>
));
React.useEffect(() => {
fetch(
"https://gateway.marvel.com/v1/public/characters?ts=1&apikey=e8aa37188987325dca0c570b01707e2c&hash=d784691874995aae3b9fb373b5a4d1da&limit=50"
)
.then((response) => response.json())
.then((data) => setCharacters(data.data.results));
}, []);
React.useEffect(() => {
forceCheck();
});
return (
<div className="App">
<h1>My Hero's</h1>
<div>{characters.length ? items : null}</div>
</div>
);
}
function Character({ img, name }) {
return (
<div style={{ height: "300px", width: "200px", backgroundColor: "purple" }}>
<h3>{name}</h3>
<img height="200" width="200" src={img} />
</div>
);
}
My problem is that when the fetch loads all the data the lazyload components load all at once. Pls Help me. I’m using react-lazyload
My codesandbox