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 ?
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
Most helpful comment
(Note these are private implementation details and will change in future versions.)