React.memo使用报错Component definition is missing display name

编程入门 行业动态 更新时间:2024-10-21 03:42:06

React.memo使用<a href=https://www.elefans.com/category/jswz/34/1771188.html style=报错Component definition is missing display name"/>

React.memo使用报错Component definition is missing display name

函数组件使用React.memo对其进行优化时,Eslint校验报错:Component definition is missing display 

const TestCom= React.memo(({ placement }) => {...
});export default TestCom;

原因:直接导出箭头函数不会给组件一个displayName

解决:

1、添加 TestCom.displayName = 'TestCom'

const TestCom= React.memo(({ placement }) => {...
});TestCom.displayName = 'TestCom';
export default TestCom;

2、导出一个常规函数,函数名为displayName

const TestCom= React.memo(function TestCom({ placement }) {...
});export default TestCom;

更多推荐

React.memo使用报错Component definition is missing display name

本文发布于:2023-11-15 17:09:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603240.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   memo   React   Component   display

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!