Submitted over 1 year ago
Rest Countries website w/ react-router, RTK query, Headless UI
@turtlecrab
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 withstyled
except forTransition
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 useTransition
withstyled
, 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 trieduseTransition
at first, but as it turned out, it works only withuseState
/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
we haveNative Name: Namibië, Namibia, Namibia, Namibia, Namibia, Namibia, Namibia, Namibia, Namibia
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 GitHubJoin 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