DEV Community

Manav Misra
Manav Misra

Posted on

Answer: Is there any practical way to call `React.createContext()` within a component?

React.createContext will return an object that holds 2 components:

  1. Provider
  2. Consumer

These 2 components can share data, the Consumer can "grab" the context data from the nearest Provider up the tree (or use the useContext hook instead of rendering a Consumer).

You should create the context object outside the…

Top comments (0)