Context in Facebook's React JS framework

By : Justin
Source: Stackoverflow.com
Question!

I'm struggling to understand how context works in Facebook's React JS framework.

When passing a specification to React.createClass, certain methods (notably event handlers) seem to require the use of React.autoBind to 'bind callbacks to the component'. Other methods (notably render()) don't have this requirement but still happily reference 'this.props' or 'this.state'.

What is the context of 'this' as used by the render() method, if it's not the component ?

By : Justin


Answers

In any component framework (not just react), event handlers need manual management of the this reference because they're registered into the DOM as a callback function, not method. In react 0.3 you could bind the this reference yourself, or you can use React.autoBind which is more efficient. In React 0.4, all event handlers get bound by the framework on their way into the DOM, so you don't have to think about it anymore.

thus the this reference is always a reference to a react component instance.



This video can help you solving your question :)
By: admin