简体   繁体   English

反应匿名组件函数 ESLint 错误

[英]React Anonymous Component Function ESLint Errors

I need help resolving these lint errors on this React anonymous function.我需要帮助解决这个 React 匿名函数上的这些 lint 错误。

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

Here are the lint errors这是 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

this resolved them. 这解决了他们。

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 }

you can add a comment eslint-disable and there will be no error 您可以添加注释eslint-disable并且不会出现错误

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React 中的 Eslint 没有纠正错误 - Eslint in React not correcting errors ESLint - 组件应编写为纯函数(反应优先/无状态函数) - ESLint - Component should be written as a pure function (react prefer/stateless function) ESLint - function 反应组件上缺少返回类型 - Typescript 错误解释 - ESLint - missing return type on function react component - Typescript error explanation React 类型文件在 React TypeScript (.tsx) 文件中不起作用 - 为 React 组件抛出 ESLint 错误 - React types files not working in React TypeScript (.tsx) file - Throwing ESLint errors for React Component 故事书因反应中的 eslint 错误而失败 - Storybook fails on eslint errors in react 匿名 function 和在 React 组件中直接调用 function 之间的区别 - Different between anonymous function and directly calling the function in a React component 如何从 React 中的组件事件中删除匿名 function? - How to remove an anonymous function from a component event in React? 匿名 function 如何在 React 组件的 onClick 中工作? - How does an anonymous function work in onClick in React component? 如何将任何匿名 function 传递给 ref 并在其他反应组件中使用它? - How to pass any anonymous function to ref and use that in other react component? React EsLint - 组件应该写为纯函数,并且在将其更改为纯函数后不能再读取该属性 - React EsLint - Component should be written as pure function and after changed it to pure function can't read the property anymore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM