REST Countries API with color theme switcher

Solution retrospective
I am very much proud of how I integrated shadcn ui select component which is using Radix UI Select Primitive, Although I am thinking of creating my own select component using Radix UI next time.
What challenges did you encounter, and how did you overcome them?The challenge that I first encounter was how to handle json data and use typescript to only fetch the data that will be displaying on the screen and filter out other unnecessary properties from the data. Here is how I tackle this problem.
import data from "./data.json"; const countries: CountryList[] = data.map((country) => { return { name: country.name, population: country.population, region: country.region as Region, capital: country.capital, flags: country.flags, }; }); ```ts **As for country detail page, here is how get the data:** ```ts export const getCountry = (name: string): CountryDetail => { const country = data.find((c) => c.name.toLowerCase() == name.toLowerCase()); if (!country) throw new Error(`Country with name ${name} does not exists`); let borderCountries = country.borders?.map((border) => getCountryByAlpha3Code(border) ); return { name: country.name, nativeName: country.nativeName, topLevelDomain: country.topLevelDomain, population: country.population, currencies: country.currencies, region: country.region, subregion: country.subregion, languages: country.languages, capital: country.capital, borderCountries: borderCountries, flags: country.flags, }; }; ```ts
Please log in to post a comment
Log in with GitHubCommunity feedback
No feedback yet. Be the first to give feedback on Syed Abdul Haseeb's solution.
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord