Button点击没有fire函数

#1

我用 “create-react-app” 生成的项目,发现Onclick button没有效果。chrome console 给出这个error:

invariant.js:38 Uncaught Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).

同样的code在其他project里就work。

import React from 'react';

const MyComponent = React.createClass({
    myClick: function () {
      alert("Hello World!");
    },

    render: function() {
      return(
        <div>
          <button onClick={this.myClick}>Click Me</button>
        </div>
      ); 
    }
});

export default MyComponent;
#2

你应该是,安装了最新版本的react
又使用旧版本的构建方法造成的。