DEV Community

variable passed through context does not change in the child when changing in the parent and vice versa

Dieldore on March 22, 2020

I learned this manual https://reactjs.org/docs/context.html And wrote this code UserContext.js: import React from 'react'; const UserContext = R...
Collapse
 
dance2die profile image
Sung M. Kim

Are you getting any errors?

getAccountData needs to bind this in constructor or should be declared with an arrow syntax.

Collapse
 
dieldore profile image
Dieldore • Edited

No mistakes
If i write

this.state = {
      id: '123',
};

then it will work.
this attaches correctly. But setState or timers do not change the object that is inside UserContext.Consumer