React useContext: A hook to make the use of react context more reader-friendly


const value = useContext(MyContext);
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.
  1. A Context provides both a consumer and a provider. When using the useContext Hook in React, one important thing to remember is to pass the whole context object, not just the consumer or provider.
  2. As mentioned in the official documentation, component calling useContext will always re-render when the context value changes. If re-rendering the component is expensive, you can optimize it by using memoization. We will cover about memoization later in the series while discussing useMemo().



Software Developer by profession, with a passion of sharing knowledge.

Love podcasts or audiobooks? Learn on the go with our new app.

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