Code Editor
Web Browser

Render functions often contain event listeners. Here's an example of an event listener in a render function:

render: function () { return ( <div onHover={myFunc}> </div> ); }

Recall that an event handler is a function that gets called in response to an event. In the above example, the event handler is myFunc.

In React, you define event handlers as property values on the instructions object. Like this:

React.createClass({ myFunc: function () { alert('Stop it. Stop hovering.'); }, render: function () { return ( <div onHover={this.myFunc}> </div>; ); } });

Notice that the object being passed to React.createClass has two properties: myFunc and render. myFunc is being used as an event handler. myFunc will be called any time that a user hovers over the rendered <div></div>.

Report a Bug
If you see a bug or any other issue with this page, please report it here.