Probably doing something stupid, but if anybody can help. I think this is undefined or something. So im trying to use setState and getting the following error.
line 20 Uncaught TypeError: Cannot read property 'setState' of undefined
import React from 'react';
class TimeoutModal extends React.Component {
constructor(props) {
super(props);
this.state = {
timeLeft: 60,
timeoutModal: true
};
}
componentDidMount() {
setInterval(() =>{
this.setState({ timeLeft: this.state.timeLeft - 1 });
}, 1000);
}
handleClick(e) {
this.setState({timeoutModal: false});
}
render() {
console.log(this.props.timeoutStatus);
return (
<div className="timeout-modal">
<div className="timeout-modal__container">
<p>Would you like to continue? {this.state.timeLeft}</p>
<button onClick={this.handleClick} className="timeout-modal__container-button">Yes</button>
</div>
</div>
);
}
}
export default TimeoutModal;