Skip to content

eddivalen/rest-countries-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frontend Mentor - REST Countries API with color theme switcher solution

Countries app is a React JS app that pulls country information from the REST Countries API and displays it in an orderly and understandable way.

This is a solution to the REST Countries API with color theme switcher challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Overview

The challenge

Users should be able to:

  • See all countries from the API on the homepage
  • Search for a country using an input field
  • Filter countries by region
  • Click on a country to see more detailed information on a separate page
  • Click through to the border countries on the detail page
  • Toggle the color scheme between light and dark mode (optional)

Screenshot

dark-screenshot light-screenshot

Links

My process

Tasks to do:

  • Init project with create-react-app
  • Build countries component
  • Build header component
  • Build filter component
  • Add router and routes feature
  • Add SASS
  • Add environment variable
  • Add React Query
  • Add Dark/Light Switcher
  • Add loading spinner
  • Sort countries alphabetically
  • Tooltip for theme switcher
  • migrate create-react-app to Vite
  • Add tests

Built with

What I learned

  • How to effectively minimize the number of API requests made with React Query.
  • Using React Query's caching feature has been a game-changer for managing the state of my app - it's much simpler and more efficient now.
  • How to use React Context API and use persisted state to manage the state of the theme switcher.

Consider the following flow:

  1. User visits the home page
  2. User clicks on a country to view its details
  3. User clicks on back button to return to home page
  4. User clicks on a different country to view its details
  5. User clicks on back button to return to home page
  6. User clicks on a different country to view its details

Screenshot of API requests before using React Query: before-react-query

Screenshot of API requests after using React Query: after-react-query

As you can see, the number of API requests is incremental before using React Query. Without React Query a new API request is made every time the user visits the home or the country details page. After using React Query, the number of API requests has been reduced to 1. This is because React Query caches the data from the first API request, and uses it for the subsequent requests.

Continued development

  • Add loader to the app, and add tests.
  • Implement react error boundaries to handle errors.
  • Migrate create-react-app to Vite.

Useful resources

Author

Acknowledgments

Midudev has been a great inspiration to me, his videos are packed with valuable information and he always motivates people by saying the phrase "A mover las manitas" which means "Let's get to work and make things happen!". I highly recommend you to check out his channel.

About

Countries app is a React JS app that pulls country information from the REST Countries API and displays it in an orderly and understandable way.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors