React basics: explaining the useContext hook
Sometimes we have data that we need to access in almost all parts of our components.
It will become a hassle to pass them down to each component, exactly where context comes in.
In this example, I'll use a specific theme for a website.
Our website ha...
h.daily-dev-tips.com4 min read
Jb Rocher
Lead Software Engineer in an Eco-Friendly Start Up
Nice one ! Something I like to do when creating these kind of providers is to export a custom hook wrapping the call to
useContext.For example :
const useTheme = () => useContext(ThemeContext);