useEffect(() => {
const fetchData = async (url: string, data: any[] = []) => {
const res = await fetch(url);
const json = await res.json();
if(json.pagination.links.next){
await fetchData(json.pagination.links.next, data)
}
data.push(json.data);
return data;
};
fetchData("https://gorest.co.in/public/v1/users").then(setData);
}, [url]);
useEffect(() => {
const fetchData = async (url: string) => {
let data: any[] = [];
do {
const res = await fetch(url);
const json = await res.json();
data.push(json.data);
url = json.pagination.links.next;
} while (url);
return data;
};
fetchData("https://gorest.co.in/public/v1/users").then(setData);
}, [url]);
any
- расставить твои типы надо. nums[i] = nums[zero]
nums[zero] = nums[i]