简体   繁体   English

return function returning预期的赋值或函数调用,而是看到一个表达式

[英]return function returning Expected an assignment or function call and instead saw an expression

I have a simple program in which i am making a simple form 我有一个简单的程序,正在其中编写一个简单的表格

import React, { Component } from "react";


class App extends Component {
  render() {
    return
    (
      <div className="container">
        <form>
          <label>First Name</label>
          <input type="text" name="firstname" placeholder="Your name.." />

          <label>Last Name</label>
          <input type="text" name="lastname" placeholder="Your last name.." />

          <label>Subject</label>
          <textarea name="subject" placeholder="Write something.."></textarea>

          <input type="button" value="Submit" />
        </form>
      </div>
    )
  }
}

export default App;

When i am returning a simple text in return then it's working properly. 当我返回简单文本时,它可以正常工作。

return and the code you're returning should be on the same line, otherwise automatic semicolon insertion will add a semicolon, thereby terminating your function unexpectedly: return和您要返回的代码应该在同一行,否则自动分号插入将添加分号,从而意外终止函数:

class App extends Component {
  render() {
    return ( // Return and '(' should be on the same line here
      <div className="container">
        <form>
          <label>First Name</label>
          <input type="text" name="firstname" placeholder="Your name.." />

          <label>Last Name</label>
          <input type="text" name="lastname" placeholder="Your last name.." />

          <label>Subject</label>
          <textarea name="subject" placeholder="Write something.."></textarea>

          <input type="button" value="Submit" />
        </form>
      </div>
    );
  }
}

More info about ASI in JS . 有关JS中的ASI的更多信息

Also I'd recommend using some kind of code formatter, like prettier . 我也建议使用某种代码格式化程序,例如prettier With default settings it will format your code and insert the semicolon the way ASI would do it, making this easier to debug. 使用默认设置,它将格式化您的代码并以ASI的方式插入分号,从而使调试更加容易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 期望赋值或函数调用,而是看到了一个表达式 - Expected an assignment or function call and instead saw an expression 期望一个赋值或函数调用,而是看到一个表达式? - Expected an assignment or function call and instead saw an expression? 期望一个赋值或函数调用,而是看到一个表达式 - Expected an assignment or function call and instead saw an expression 期望赋值或函数调用,但在函数中看到表达式错误 - Expected an assignment or function call and instead saw an expression error in function Javascript:JSHint:需要一个赋值或函数调用,而是看到一个表达式 - Javascript: JSHint: Expected an assignment or function call and instead saw an expression 错误-预期分配或函数调用,而是看到一个表达式 - Error - Expected an assignment or function call and instead saw an expression ReactJS错误:“预期分配或函数调用,而是看到了一个表达式” - ReactJS error: “Expected an assignment or function call and instead saw an expression” 警告带有主干的JSHint:预期分配或函数调用,而是看到一个表达式 - Warning JSHint with backbone : Expected an assignment or function call and instead saw an expression 错误:预期分配或函数调用,而是看到一个表达式 - Error: expected an assignment or function call and instead saw an expression 期望一个赋值或函数调用,而是在定义接口时看到一个表达式 - Expected an assignment or function call and instead saw an expression when defining interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM