Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 1 year ago

REST Countries API with dark mode ft. React TS, Query, Router, Parcel

parcel, react, tanstack-query, typescript, react-router
Josh Javier•950
@joshjavier
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


What are you most proud of, and what would you do differently next time?

I'm glad I gave this challenge another shot for the sake of learning. I implemented data fetching and caching with React Query, made general UX improvements, and even tried an awesome build tool called Parcel.

What challenges did you encounter, and how did you overcome them?

In my original solution, the theme flickers on page load from a blank white page, then to dark mode. This is because the logic for detecting the user's theme preference is located in the theme switcher component, so only after React is loaded does the theme kick in.

To solve this issue, I placed a script tag in the head tag which detects the user's theme preference and sets it as early as possible before styles are applied. Generally, blocking JavaScript is bad, but in this case the code is relatively small and greatly enhances UX, so it's a fair tradeoff.

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Josh Javier'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

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

Frontend Mentor

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

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