0

I came across a scenario wherein i was making an app entirely using React hooks.

I had to use certain NPM libraries in the app which were not hooks compatible. To avoid prop drilling, i plan to use useContext. Since some of my components which were using non-hooks compatible npm libraries had to be class based.

Using React-context api along with useContext was one of the sensible recourse.

Following is a very basic example for any-one trying to use useContext as Context consumer along with Context Provider.

CODE SANDBOX

ryan
  • 694
  • 9
  • 23
  • what's the question? – iamaatoh Jun 19 '20 at 13:09
  • This is more of a sharing info rather than posting a question. The sandbox shows a basic example of useContext working with React context API. Like how i struggled for a day to get it working, this might be useful for someone. – ryan Jun 19 '20 at 13:44
  • is it related to this one? https://stackoverflow.com/questions/62464615/difference-between-class-contexttype-and-context-consumer-with-working-example - that might be a better place to put it? easier for people to find – iamaatoh Jun 19 '20 at 14:30

0 Answers0