TypeError: Cannot read property ‘count.’ of undefined

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

i have a problem with the interval, the console give me the next error: TypeError: Cannot read property ‘count’ of undefined. thanks for your help!

Answer

componentDidMount does not receive props in arguments. Try checking props as below:

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

Leave a Reply

Your email address will not be published. Required fields are marked *