REST Countries API web app using React Hooks, props and router-dom.
Design comparison
Solution retrospective
please where can i learn prop drilling effectively and how to use context api in react.
Community feedback
- @zuolizhuPosted about 4 years ago
Hey @buchi,
Nice job on this challenge π!
prop drilling
itself is not effective at all π, that's why people created state management tools for handling passing props crossing components.However, if you want to stick with props and not introducing extra complex, you can do
state lifting
, π official doc you can check it out. In your example, instead of fetching all the countries in yourCountry.jsx
, you can fetching it in the upper components, which is yourApp.js
component, and then passing down to other components.Another tool you can try (and I highly recommended) is Zustand for global statement management, super easy to setup and works just fine π.
You can also use some tools like React Query or SWR, those tools have built in cache you can use, so instead of save the fetched data into state, save it as cache and use it in your components.
Hope my answer helps and happy coding π!
1
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