预期的赋值或函数调用:无未使用的表达式ReactJS [英] expected assignment or function call: no-unused-expressions ReactJS

查看:181
本文介绍了预期的赋值或函数调用:无未使用的表达式ReactJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class Game extends Component 
{
  constructor() 
  {
    super()
    this.state = {
      speed: 0
    }
    //firebaseInit()
  }
  render()
  {
    return 
    (
      <div>
        <h1>The Score is {this.state.speed};</h1>
      </div>
    )
  }
}

export default Game;

我是React的新手,对于此代码,它给出了此错误

I am new to React and for this code its giving this error

Expected an assignment or function call and instead saw an expression  no-unused-expressions

不明白哪里出了问题,请帮忙

Dont understand where getting wrong, please help

推荐答案

之所以会发生这种情况,是因为将return的括号放在了下一行.如果您在编写不带分号的js并使用在下一行放置大括号的样式,这可能是一个常见错误.

This happens because you put bracket of return on the next line. That might be a common mistake if you write js without semicolons and use a style where you put opened braces on the next line.

解释器认为您返回undefined,因此不检查您的下一行.这就是return运算符.

Interpreter thinks that you return undefined and doesn't check your next line. That's the return operator thing.

将打开的括号与return放在同一行.

Put your opened bracket on the same line with the return.

这篇关于预期的赋值或函数调用:无未使用的表达式ReactJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆