使用 babel 编译时出现 ESLint 错误:
第 28 行:期望赋值或函数调用,却看到了一个表达式 no-unused-expressions
第 29 行:期望赋值或函数调用,却看到了一个表达式 no-unused-expressions
知道如何摆脱这些同时让我的计时器仍然按预期工作吗?或者你有更好的方法让我做我的计时器吗?
class RequestTimer extends Component {
constructor(props) {
super(props);
this.state = {
seconds: 0,
minutes: 0,
hours: 0
}
this.getTime = this.getTime.bind(this);
}
getTime() {
let second = this.state.seconds
let minute = this.state.minutes;
let hour = this.state.hours;
this.state.seconds % 59 === 0 && this.state.seconds !== 0 ? minute += 1:null;
this.state.minutes % 59 === 0 && this.state.seconds % 59 === 0 && this.state.minutes !== 0 ? (hour += 1, minute = 0):null;
this.setState({
seconds: second +=1,
minutes: minute,
hours: hour
})
}
componentDidMount() {
this.timer = setInterval(this.getTime, 1000)
}
render() {
return (
<TimerContainer>
<h2>Last Request:</h2>
<p>{this.state.hours}h {this.state.minutes}m {this.state.seconds % 60}s</p>
</TimerContainer>
)
}
}