[英]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.