[英]ESLint: Unexpected block statement surrounding arrow body. (arrow-body-style)
This rule, triggered by the below snippet of code, is most confusing (to me - and others it appears).由以下代码片段触发的这条规则最令人困惑(对我和其他人来说)。 If I remove the curlies, it breaks.如果我去除卷曲,它就会破裂。 If I add parens around the block, it breaks.如果我在块周围添加括号,它就会中断。 What to do?该怎么办?
const MainLayout = (props) => {
return (
<div className="main">
<Header />
<Navbar />
<Content>
{props.children}
</Content>
<Footer />
</div>
);
};
This is ESLint v4.13.1这是 ESLint v4.13.1
if you're just returning a value immediately, you don't need a return
statement in an arrow function. 如果您只是立即返回一个值,则不需要在箭头函数中使用return
语句。 Just put the value directly after the arrow. 只需将值直接放在箭头后面。
And when there's just a single argument, you don't need parentheses around the argument list. 而且,当只有一个参数时,不需要在参数列表中加上括号。
const MainLayout = props => (
<div className="main">
<Header />
<Navbar />
<Content>
{props.children}
</Content>
<Footer />
</div>
);
you don't need retun just add ( instead of { . Like this... 你不需要retun只是添加的(不是{。就像这个...
const Card = props => (
<View style={styles.containerStyle}>{props.children}</View>
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.