如何纠正React代码中的解析错误

How to rectify the parse error in the React code

提问人:Satish Medapalli 提问时间:11/17/2023 更新时间:11/17/2023 访问量:17

问:

// Write your code here
import {Component} from 'react'
import './index.css'

class Speedometer extends Component {
  state = {count: 0}

  Increase = () => {
    const {count} = this.state

    if (count < 200) {
      this.setState(prevState => ({count: prevState.count + 10}))
    }
  }

  Decrease = () => {
    const {count} = this.state

    if (count > 0) {
      this.setState(prevState => ({count: prevState.count - 10}))
    }
  }

  render() {
    const {count} = this.state
    return (
      //html code
    )
  }
}
export default Speedometer
Error:

Failed to compile.

src/App.js
  Line 1:25:  Parse errors in imported module './components/Speedometer': Line 8: Missing semicolon.

   6 |   state= {count:0}
   7 | Increase=()=>{
>  8 |     this.prevState=>({prevState.count+10})
     |                   ^
   9 | }
  10 |   render() {
  11 |     const {count}=this.state (8:19)  import/no-named-as-default
  Line 1:25:  Parse errors in imported module './components/Speedometer': Line 8: Missing semicolon.

   
  

我已经尝试了几次尝试来修复此错误,但找不到解析错误。特别是在 8 行的箭头函数不知道为什么会出现错误。实际上什么是解析错误?

HTML CSS 反应JS

评论

1赞 jonrsharpe 11/17/2023
您的错误与您显示的代码不匹配。“解析错误”意味着你输入的内容实际上并不是最低限度的 JavaScript,所以它甚至无法尝试运行它。
0赞 Peter B 11/17/2023
错误中的代码与您发布的代码不匹配。您确定错误中的代码根本不存在于任何文件中吗?您是否保存了所有文件,或者您可能忘记了保存文件,以便解析器看到编辑器中已更改但未保存的旧代码?

答: 暂无答案