handleEvent, onEvent and this.props.onEvent

It’s the code about Talker.js

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

```

var React = require(‘react’);
var ReactDOM = require(‘react-dom’);
var Button = require(’./Button’);

var Talker = React.createClass({
handleClick: function () {
for (var speech = ‘’, i = 0; i < 10000; i++) {
speech += 'blah ';
}
alert(speech);
},

render: function () {
return ;
}
});

ReactDOM.render(
,
document.getElementById(‘app’)
);

<do not remove the three backticks above>

And here's the code about Button.js:

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Look to the right of this box. That is how your post will look to everyone else.>

<Below this line, add a link to the EXACT exercise that you are stuck at.>


<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>


<do not remove the three backticks below>

var React = require(‘react’);

var Button = React.createClass({
render: function () {
return (

Click me!

);
}
});

module.exports = Button;

<do not remove the three backticks above>

Who could explain me why, in the Button.js, I need to code:

Click me!

What does it mean there {this.props.onClick}? 
Or, who wants could explain me the entire reasonment under this exercise. I think to get the argument, but I'm not sure at all.

Cheers!
1 Like

I am having the same question…

It is a reference to the prop name, onClick which is defined in the render function of the parent component. The prop in the parent component is {this.handleClick} which is passed to the Button component so that when a user clicks the button, it triggers the event handler, handleClick.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.