Recharts eslint 错误在 props 验证中丢失

问题描述

我是 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...