mirror of
https://github.com/vercel/next-learn.git
synced 2026-06-11 09:51:47 +00:00
Fix restcountries API (#53)
This commit is contained in:
@@ -74,7 +74,7 @@ export default function Start({ countries }) {
|
||||
|
||||
<ul className={styles.countries}>
|
||||
{results.map((country) => (
|
||||
<li key={country.alpha2Code} className={styles.country}>
|
||||
<li key={country.cca2} className={styles.country}>
|
||||
<p>
|
||||
{country.name} - {country.population.toLocaleString()}
|
||||
</p>
|
||||
@@ -113,12 +113,16 @@ export default function Start({ countries }) {
|
||||
}
|
||||
|
||||
export async function getServerSideProps() {
|
||||
const response = await fetch("https://restcountries.eu/rest/v2/all")
|
||||
const response = await fetch("https://restcountries.com/v3.1/all")
|
||||
const countries = await response.json()
|
||||
|
||||
return {
|
||||
props: {
|
||||
countries
|
||||
countries: countries.map((country) => ({
|
||||
name: country.name.common,
|
||||
cca2: country.cca2,
|
||||
population: country.population,
|
||||
})),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ export default function Start({ countries }) {
|
||||
|
||||
<ul className={styles.countries}>
|
||||
{results.map((country) => (
|
||||
<li key={country.alpha2Code} className={styles.country}>
|
||||
<li key={country.cca2} className={styles.country}>
|
||||
<p>
|
||||
{country.name} - {country.population.toLocaleString()}
|
||||
</p>
|
||||
@@ -100,12 +100,16 @@ export default function Start({ countries }) {
|
||||
}
|
||||
|
||||
export async function getServerSideProps() {
|
||||
const response = await fetch('https://restcountries.eu/rest/v2/all');
|
||||
const response = await fetch('https://restcountries.com/v3.1/all');
|
||||
const countries = await response.json();
|
||||
|
||||
return {
|
||||
props: {
|
||||
countries,
|
||||
countries: countries.map((country) => ({
|
||||
name: country.name.common,
|
||||
cca2: country.cca2,
|
||||
population: country.population,
|
||||
})),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user