115
rated 0 times
[
120]
[
5]
/ answers: 1 / hits: 22878
/ 5 Years ago, sat, february 2, 2019, 12:00:00
How can I access objects inside of React Context inside a function of a Class Component.
I've got the following React Component
import StoreContext from '../../context/StoreContext'
class ProductForm extends Component {
static contextType = StoreContext
constructor(props) {
super(props);
}
handleOptionChange(event) {
const test = this.contextType.client.testObject
}
I've tried accessing the client
object inside the context like this but It doesn't work because it says cant read the property of undefined.
I'm wondering where my mistake is.
More From » reactjs