React代码找错试题 求助

Z.Chen 2021-07-24 14:18:00
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>
        );
    }
}

请问上述代码哪里有问题啊?

...全文
534 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
FnaticE 2021-07-26
  • 打赏
  • 举报
回复

super(props);是不是漏了?

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧