React: Expected an assignment or function call and instead saw an expression

前端 未结 8 1250
一个人的身影
一个人的身影 2020-11-27 05:40

I am trying to fix this lint error at line const def = (props) => { in following sample code.

const propTypes = {
prop1: PropTypes.string,
pr         


        
相关标签:
8条回答
  • 2020-11-27 06:18

    The return statements should place in one line. Or the other option is to remove the curly brackets that bound the HTML statement.

    example:

    return posts.map((post, index) =>
        <div key={index}>
          <h3>{post.title}</h3>
          <p>{post.body}</p>
        </div>
    );
    
    0 讨论(0)
  • 2020-11-27 06:21

    You must return something

    instead of this (this is not the right way)

    const def = (props) => { <div></div> };
    

    try

    const def = (props) => ( <div></div> );
    

    or use return statement

    const def = (props) => { return  <div></div> };
    
    0 讨论(0)
提交回复
热议问题