【问题标题】:React Anonymous Component Function ESLint ErrorsReact 匿名组件函数 ESLint 错误
【发布时间】:2019-03-30 15:22:29
【问题描述】:

我需要帮助解决这个 React 匿名函数上的这些 lint 错误。

export default {
  "text": () => { return <div className="item-icon">txt</div>; },
  "image": (props) => { return <img className="preview-img" src={props.src} alt=''/>; }
};

这是 lint 错误

  4:11  error  Component definition is missing display name  react/display-name
  5:12  error  Component definition is missing display name  react/display-name
  5:72  error  'src' is missing in props validation          react/prop-types

【问题讨论】:

    标签: reactjs eslint


    【解决方案1】:

    这解决了他们。

    const text = () => { return <div className="item-icon">txt</div>; };
    text.displayName = 'text';
    
    const image = (props) => { return <img className="preview-img" src={props.src} alt=''/>; }
    image.displayName = "image";
    image.propTypes = {
      src: PropTypes.string
    };
    
    export default { text, image }
    

    【讨论】:

      猜你喜欢
      • 2017-07-07
      • 2020-09-29
      • 1970-01-01
      • 2021-05-07
      • 2016-10-02
      • 2016-06-20
      • 1970-01-01
      • 2018-09-14
      • 2021-07-13
      相关资源
      最近更新 更多