Code not working


#1



//button.js
var React = require('react');

var Button = React.createClass({
  render: function () {
    return (
      <button onClick={this.props.talk}>
        Click me!
      </button>
    );
  }
});

module.exports = Button;

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

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

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

why isn't this working ?


Put an Event Handler in a Component Class
#2

Have you added foo = 'bar' to button ?


#3

you missed something in Talker.js render function:

render: function () {
    return <Button talk={this.talk}/>;
}

#4

Thanks! I made the same mistake. Now it works for me too.


#6

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