Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is _instance pointing to _ReactInternalInstance & _ReactInternalInstance pointing to _instance, expected Structure ? #8708

Closed
sanjay1909 opened this issue Jan 7, 2017 · 3 comments

Comments

@sanjay1909
Copy link

sanjay1909 commented Jan 7, 2017

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 ?

@aweary
Copy link
Contributor

aweary commented Jan 7, 2017

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.

@gaearon
Copy link
Collaborator

gaearon commented Jan 7, 2017

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

@sanjay1909
Copy link
Author

Thanks for the clarification, it was really helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants