问题描述
我是 React 开发新手。 eslint 提供以下错误
Line 37:11: 'x' is missing in props validation react/prop-types
Line 37:14: 'y' is missing in props validation react/prop-types
...
指的是以下代码片段的第 2 行
const customLabel = (props) => {
const { x,y,width,height,value } = props;
return (
<text
x={x} y={y} fill={"white"}>
{value.toLocaleString()}
</text>
);
};
customLabel
用于 recharts 库
<Bar
dataKey={Metadata.dataKey}
name={Metadata.name}
unit={data.xAxisInfo.unit}>
<LabelList dataKey={Metadata.dataKey} content={customLabel} />
</Bar>
我在 <LabelList content={customLabel} />
组件中使用的 <Bar />
与 the example in the documentation 完全一样。我无法在接口中声明 prop 类型,因为 customLabel
然后无法分配给 ContentRenderer<LabelProps>
。不幸的是,抑制 eslint 不是一种选择。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)