[英]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.