meaning loop over the page.
Put the pageNumber and the allCountries array in the global scope (and use let instead of const).
let pageNumber = 1;
let allCountries = [];
export function getAllCountries(){
let url = 'https://something.com';
let fullUrl = url + '?page=' + pageNumber;
//run the fetch using fullUrl. do what ever you need, save the results in a global variable then in the end:
allCountries.push(countries);
allCountries = allCountries.flat();
if(hasNextPage){
pageNumber++;
return getAllCountries();
}
return allCountries;
}