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

末鹿安然 提交于 2019-12-24 07:49:03

问题


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


回答1:


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>
  );



回答2:


you don't need retun just add ( instead of { . Like this...

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


来源:https://stackoverflow.com/questions/48019945/eslint-unexpected-block-statement-surrounding-arrow-body-arrow-body-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!