Skip to content
  • Learning paths
  • Challenges
  • Solutions
  • Articles
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 4 years ago

Rest Country API using React

positivevibes•205
@posivibez
A solution to the REST Countries API with color theme switcher challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I wanted to jump ahead to an advanced challenge to push myself. I was able to get everything functional and it runs well. I'm probably not using some React best practices though. Below are a few notes on my code. Recommendations to improve are always very appreciated.

  • To style the components in Light and Dark mode, I'm passing the theme value to the components with props and then conditionally giving them different classes based on that
 props.theme value. This doesn't feel like the most elegant way to do it.

  • I tried to set up the logic for filtering and search simultaneously, or searching through only the filtered countries. I.e. if you select Africa for a filter and then search "Be" it will only show countries that match both the search and the filter. It seemed like the API did not allow you to call data from it with both of these criteria applied simultaneously. So for now this functionality is not present. Does anyone know if that is possible and I was not calling the API correctly for this? (I suppose I could store the filter data from the API in a state and then apply the search "locally" to that as opposed to doing both directly from the API.)

Thanks so much.

Code
Couldn’t fetch repository

Please log in to post a comment

Log in with GitHub

Community feedback

  • Grace•32,130
    @grace-snow
    Posted over 4 years ago

    Hey

    In answer to your first question, it sounds like you're making the theme switching harder than it needs to be.

    Usually you either have two variables objects and simply use those variables throughout your styles (most common method with frameworks like this). This is exactly what you're doing in mobile styles so you must know how to do it I'd have thought.

    Alternatively, you can toggle a class on the body and then change styles as needed when that class is present.

    I hope this gives you some ideas

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Frontend Mentor for Teams

Frontend Mentor for Teams helps companies and schools onboard and train developers through project-based learning. Our industry-standard projects give developers hands-on experience tackling real coding problems, helping them master their craft.

If you work in a company or are a student in a coding school, feel free to share Frontend Mentor for Teams with your manager or instructor, as they may use it to help with your coding education.

Learn more

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub