类型错误:无法读取属性“计数”。未定义的

时间:2021-03-04 13:13:06

标签: javascript html node.js reactjs

componentDidMount(props) {
    this.interval = setInterval(() => {
        if (props.count !== 0) {
            this.stateHandler()
        }
    }, 1000)
}

我的间隔有问题,控制台给我下一个错误: 类型错误:无法读取未定义的属性“计数”。 感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

componentDidMount 在参数中不接收 props。尝试检查道具如下:

componentDidMount() {
    this.interval = setInterval(() => {
        if (this.props.count !== 0) {
            this.stateHandler()
        }
    }, 1000)
}