我使用命令来创建我的项目,按钮没有触发create-react-app
对我来说真的很奇怪。onClick
我看到了这个我以前从未见过的错误
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
不确定此错误是否导致按钮单击未触发。代码非常简单,在其他项目中运行良好。
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;