React: Is _instance pointing to _ReactInternalInstance & _ReactInternalInstance pointing to _instance, expected Structure ?

Created on 7 Jan 2017  ·  3Comments  ·  Source: facebook/react

screen shot 2017-01-07 at 09 26 55

I was playing with the examples to understand the internal code flow of React's setState.
I noticed that ReactCompositeComponentWrapper Object had reference to _instance Object which in turn had reference to the same (screenshot's console) ReactCompositeComponentWrapper Object as _ReactInternalInstance. Is that an expected structure ?

Question

Most helpful comment

(Note these are private implementation details and will change in future versions.)

All 3 comments

Yes, it is intentionally a doubly linked structure. ReactCompositeComponentWrapper is an internal only and wraps user-defined composite components. It holds a reference to the instance of the user-defined component that is defined when it is mounted. Then ReactInstanceMap is used to store a reference to the internal wrapper on the public instance.

If you look at ReactInstanceMap it has some more information in the doc comments

ReactInstanceMap maintains a mapping from a public facing stateful instance (key) and the internal representation (value). This allows public methods to accept the user facing instance as an argument and map them back to internal methods.

(Note these are private implementation details and will change in future versions.)

Thanks for the clarification, it was really helpful

Was this page helpful?
0 / 5 - 0 ratings