87,907
社区成员
发帖
与我相关
我的任务
分享
class VaisalaDummyComponent extends React.Component {
constructor(props) {
// set the default internal state
this.state = {
clicks: 0
};
}
componentDidMount() {
this.refs.vaisalaComponentDiv.addEventListener('click', this.clickHandler);
}
componentWillUnmount() {
this.refs.vaisalaComponentDiv.removeEventListener('click', this.clickHandler);
}
clickHandler() {
this.setState({
clicks: this.clicks + 1
});
}
render() {
let children = this.props.children;
return (
<div className="Vaisala-dummy-component" ref="vaisalaComponentDiv">
<h2>Vaisala Component ({this.state.clicks} clicks})</h2>
<h3>{this.props.headerText}</h3>
{children}
</div>
);
}
}
请问上述代码哪里有问题啊?
super(props);是不是漏了?