Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Rest Countries website w/ react-router, RTK query, Headless UI

#react#react-router#redux-toolkit#styled-components
turtlecrab 550

@turtlecrab

Desktop design screenshot for the REST Countries API with color theme switcher coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
  • API
4advanced
View challenge

Design comparison


SolutionDesign

Solution retrospective


Stuff used:

  • react-router for storing filter states in search params, had to write a custom hook for it. It's a shame react-router doesn't have such hook built-in.
  • RTK query for fetching, I like that it stores cache right in the redux store, so it's easy to see how it's organized.
  • Headless UI for region select. It worked fine with styled except for Transition component that receives class names as props, so I had to create global css classes and pass their names. If you know a better way to use Transition with styled, please share.
  • useDeferredValue for keeping the input field responsive while the long list of countries is being rerendered. I could have used debouncing instead, or paginate the list so it's not very long, but wanted to try these new hooks (actually I tried useTransition at first, but as it turned out, it works only with useState/useReducer states, and as I said above, my state was in the search params via a custom hook)
  • added not so noticeable animation to the magnifying glass icon when the country list is stale (the new list is deferred and being rerendered)
  • since it's too boring to search only in the country names, it also searches in translations provided by the api.
  • duplicate native names are removed, so instead of
    Native Name: Namibië, Namibia, Namibia, Namibia, Namibia, Namibia, Namibia, Namibia, Namibia
    
    we have
    Native Name: Namibië, Namibia
    
  • also had idea of adding the settings menu where we could enable/disable some options like search in translations, showing only independent states, search only from the start of a word etc. Maybe will implement it some day.

Community feedback

Please log in to post a comment

Log in with GitHub
Discord logo

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