Put an Event Handler in a Component Class - Who can explain me exactly the reasoning?


#1



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



var Talker = React.createClass({
  talk: function () {
  for (var speech = '', i = 0; i < 10000; i++) {
    speech += 'blah ';
  }
  alert(speech);
},
  render: function () {
    return <Button talk={this.talk}/>;
  }
});

ReactDOM.render(
  <Talker />,
  document.getElementById('app')
);

I found this solution that works very well in an other post on the forum. But the post says just to add

talk={this.talk}/>;

to the component instance, it doesn't explain why it works. Who could help me with an explanation?!
Why I need to add a property with the name of the function I created on the React.createClass, and the value with the same function?

Cheers!


#2

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