Image for post
Image for post
Photo by Emile Perron on Unsplash

I don’t want to lose too much time explaining the concept of Context; there are simply too many great explanations of it out there like here, here, here, here, here, and here. But I can’t just throw some code at you so here we go: Context allows you to access data anywhere and avoid excessive prop drilling in your app. The React docs do a great job summarizing the concept:

Context is designed to share data that can be considered “global” for a tree of React components, such as the current authenticated user, theme, or preferred language.

It should not be used as a substitute for Redux but rather, as the quote above suggests, as a way to distribute certain items like a user or theme to your components at varying levels of your React Component tree. The example below shows Context all in one file so “SingleFile” is a better name than “SinglePage” but whatever. The point is that everything is in one file so that you can see what’s happening despite the fact that you’d never really do it this way. …

Colin McNamara

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store