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:
import however many contexts you need to consume in the class.
Grab the current values by using contextName = SomeContext.Consumer['_currentValue'];
Reference any of the variables that exist in that context.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I freely admit that
useContextis one of the benefits of Hooks. You can use the Context API with Hooks or with class-based components. ButuseContextjust "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:
importhowever many contexts you need to consume in the class.Grab the current values by using
contextName = SomeContext.Consumer['_currentValue'];Reference any of the variables that exist in that context.