ย
๐ ๊นํ๋ธ : https://github.com/Park-Yuyeong/account-book
โ๏ธ ์น์ฌ์ดํธ : https://country-card-sooty.vercel.app
ย
ย
class CountryAPI {
private client: AxiosInstance;
constructor(client: AxiosInstance) {
this.client = client;
}
async getCountries() {
try {
const path = "/all";
const response = await this.client.get<TCountry[]>(path);
const result = response.data;
return result;
} catch (error) {
console.error("Country API Error => ", error);
}
}
}
GET ๋ฉ์๋๋ฅผ ํ์ฉํ API ํธ์ถย
const [countries, setCountries] = useState<TCountry[]>([]);
const changeCountryCardState = (country: TCountry) => {
const newCountries = countries.map((prevCountry) =>
prevCountry.name.common === country.name.common
? { ...prevCountry, selected: !prevCountry.selected }
: prevCountry
);
setCountries(newCountries);
};
selected ์์ฑ์ด ๋ณํ๋๋ก ๊ตฌํselected ๊ฐ์ด true๋ฉด Favorite Countries์ ๋๋ผ ์นด๋ ์์นselected ๊ฐ์ด false๋ฉด Countries์ ๋๋ผ ์นด๋ ์์น