
rest-countries-api-with-color-theme-switcher
Design comparison
Solution retrospective
Most Proud Of: Implementing dark mode toggle with persistence using Local Storage. Handling dynamic routing to display country details. Ensuring a responsive and accessible UI with Tailwind CSS.
What I’d Do Differently: Optimize API requests for better performance. Improve error handling for API failures. Add search debounce to enhance user experience.
What challenges did you encounter, and how did you overcome them?Dark Mode Reset on Refresh
Challenge: The dark mode state would reset after a page refresh. Solution: Used Local Storage to persist the user's theme preference. Dynamic Routing for Country Details
Challenge: Ensuring correct data fetching and handling page reloads. Solution: Used React Router’s useParams to fetch country details dynamically. Styling & Responsiveness
Challenge: Making the UI look clean and accessible on all screen sizes. Solution
What specific areas of your project would you like help with?Right now, my project is complete, but I would appreciate feedback on:
Accessibility & UX – Is the dark mode toggle intuitive? Are there any improvements for a better user experience? Performance Optimization – Are there ways to improve API handling or reduce unnecessary re-renders? Best Practices – Any suggestions on improving my React code structure, state management, or component organization?
Please log in to post a comment
Log in with GitHubCommunity feedback
- @ippotheboxer
Some bugs I noticed:
- Light and dark mode don't work. The whole app is essentially staying in dark mode, only the region filter and search get changed when I toggle the mode. You're using local storage to store darkmode, even when I change it to false, it doesn't change to light mode. I think this could be because local storage sets everything as text, so maybe true is being read as "true" rather than a boolean. For example, you do:
const [darkMode, setDarkMode] = useState<boolean>(() => { return localStorage.getItem('darkmode' ) === "true" });
But you should check
localStorage.getItem('darkmode' ) === true
, since it's a boolean. Also instead of returning it like this, just setuseState<boolean>(false)
, and you could use useEffect to detect if the darkmode in local storage changes. You're basically always returning dark mode as true instead of reading it.- On dark mode, I can hardly read the text. On dark mode the text is supposed to be white, using a black and dark grey text makes it pretty hard to read, and when you search, I can't see the text that I'm writing.
- Between the large and small screen sizes, there's a sudden jump to 1 per grid then to 3. So when it first changes to 3, the height is way too high for the flags and all the flags don't contain the whole flag, just a small zoomed-in portion of the flag (this can be fixed with object-fit). I think it would look better if it switched to 2, and then 3.
- I feel like using local storage to set the theme could be a bit overcomplicated: I think it would be better to use a context to store the theme, and maybe if it changes you could then write to local storage.
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