最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ESLint: Unexpected block statement surrounding arrow body. (arrow-body-style) - Stack Overflow

programmeradmin2浏览0评论

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

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

Share Improve this question asked Dec 29, 2017 at 8:55 maashamaasha 1,9953 gold badges25 silver badges47 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 13

if you're just returning a value immediately, you don't need a return statement in an arrow function. 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...

const Card = props => (
  <View style={styles.containerStyle}>{props.children}</View>
);

Remove the above extension from your VS Code editor issue will be soved

发布评论

评论列表(0)

  1. 暂无评论