React components and reaching for state

Instances of a React Component are created internally in React when rendering. These instances are reused in subsequent renders, and can be accessed in your component methods as this. The only way to get a handle to a React Component instance outside of React is by storing the return value of ReactDOM.render. Inside other Components, you may use refs to achieve the same result.

Source: Component API | React

It would be a lot easier if a reference to the component was saved on the DOM element itself.

Related to this, there’s this question on stackoverflow:

For the purposes of debugging in the console, is there any mechanism available in React to use a DOM element instance to get the backing React component?

Source: React – getting a component from a DOM element for debugging



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s