DEV Community

Discussion on: When Should You Convert Your Classes to Hooks??

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

I freely admit that useContext is one of the benefits of Hooks. You can use the Context API with Hooks or with class-based components. But useContext just "feels" easier.

IMHO, the biggest annoyance of the Context API in classes is that it's very obtuse to figure out how you would consume multiple contexts inside a single class. If you're not familiar with it, I outlined the process here: dev.to/bytebodger/a-context-api-fr...

The Cliff's Notes are this:

  1. import however many contexts you need to consume in the class.

  2. Grab the current values by using contextName = SomeContext.Consumer['_currentValue'];

  3. Reference any of the variables that exist in that context.