Retrouvez les données de plusieurs pages d'une API dans React Native
React.useEffect(() => {
const getAllGames = async(page: number|null): void => {
if (Number.isInteger(page)){
const result = await fetch(apiURL + "/games?page="+page)
const data = await result.json()
const { results: games } = data;
if (data.next) {
setTimeout(
getAllGames(
parseInt(data.next.charAt(data.next.length-1))), 10000)
}
setGames(previousGames => [...games, ...previousGames]);
}
}
getAllGames(1)
}, []);
Puzzled Puffin