re: Build your own MobX-like state management library in 40 lines of code VIEW POST

re: Hi Nathan! Thanks for your interest! Perhaps it's me, but I'm not quite sure what you mean : ) By "observable object", do you mean the object wrap...

Because currentlyRenderedComponent is a global variable, this can occur :

  • The rendering of a parent starts, currentlyRenderedComponent = parent component.
  • The rendering of a child starts, currentlyRenderedComponent = child component.
  • The rendering of the child is done, currentlyRenderedComponent = undefined
  • The rendering of the parent continues, an observable object is accessed, but currentlyRenderedComponent === undefined so it considers that we are outside of a component.

Then, when the observable object is modified, the parent component is not rendered again. A fix for that is replacing currentlyRenderedComponent by a stack in which we push a component when it starts rendering and we pop it when it's done.

code of conduct - report abuse