[英]React - Getting "Component definition is missing display name" error when using React.memo
Why am I getting the ESLint error Component definition is missing display name
on this code:为什么我收到 ESLint 错误
Component definition is missing display name
on this code:
export const Button = React.memo(props => {
//...
});
Is this a false positive or real error?这是误报还是真正的错误?
Exporting an arrow function directly doesn't give the component a displayName
, but if you export a regular function the function name will be used as displayName
.直接导出箭头 function 不会为组件提供
displayName
,但如果导出常规 function ,则 function 名称将用作displayName
。
You can also put the function in a variable, set the displayName
on the function manually, and then export it.也可以把function放在一个变量里,在function上手动设置
displayName
,然后导出。
const Button = React.memo(props => {
//...
});
Button.displayName = 'Button';
export Button;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.