Design comparison
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.
Community feedback
- @grace-snowPosted almost 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
1@posivibezPosted almost 4 years agoThanks very much Grace. I'm in the middle of a React course now, so planning to refactor the code here once I'm done.
Thanks for pointing out these two methods to accomplish this, will definitely refer back to your suggestions. : )
0
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