I create this function startStop for such button to start and pause a timer. The error is "Line 108:22: 'sessionLength' is not defined no-undef". I think it might have to do with binding? but what's wrong?
import React, { Component } from 'react'; import './App.css'; class App extends Component { state = { breakLength: 5, sessionLength: 25, timerState: "paused", } constructor(props) { super(props) this.startStop = this.startStop.bind(this) } startStop() { if (this.state.timerState === "paused") { this.setState({ timerState: setInterval(() => decrement(), 1000) }, function () {console.log(this.state.timerState)}) } else if (this.state.timerState !== "paused") { console.log(this.state.timerState) clearInterval(this.state.timerState) this.setState({ timerState: "paused" }, function () {console.log(this.state.timerState)}) } this.setState({ sessionLength: sessionLength - remaining }, function () {console.log(this.state.sessionLength)}) } https://stackoverflow.com/questions/65623319/react-function-state-is-not-defined-no-undef January 08, 2021 at 12:06PM
没有评论:
发表评论