反应:检查器不是一个函数 [英] React: checker is not a function
问题描述
我在我的 React 应用程序的控制台中收到这条奇怪的警告消息.
I'm getting this weird warning message in the console for my React app.
Warning: Failed propType: checker is not a function 检查Chart
的render方法.
Warning: Failed propType: checker is not a function Check the render method of
Chart
.
我根本没有任何检查方法.如果我删除我的 propTypes
,警告就会消失.有什么想法吗?
I do not have any checker method at all. If I remove my propTypes
, the warning is gone. Any ideas?
我的反应组件:
var Chart = React.createClass({
//...
propTypes: {
legend: React.PropTypes.bool,
max: React.PropTypes.number,
min: React.PropTypes.number,
series: React.PropTypes.arrayOf(
React.PropTypes.shape({
label: React.PropTypes.string,
values: React.PropTypes.arrayOf(
React.PropTypes.arrayOf(
React.PropTypes.oneOfType(
React.PropTypes.number,
React.PropTypes.object // Date
)
)
),
colorIndex: React.PropTypes.string
})
).isRequired,
threshold: React.PropTypes.number,
type: React.PropTypes.oneOf(['line', 'bar', 'area']),
units: React.PropTypes.string,
xAxis: React.PropTypes.arrayOf(React.PropTypes.string)
},
render: function() {
return (<svg>...</svg>);
}
//...
});
我发送到 Chart 组件的有效载荷是这个:
The payload I send to the Chart component is this one:
var series = [
{label: 'first', values: [[5,2], [4,3], [3,3], [2,2], [1,1]], colorIndex: "graph-1"},
{label: 'second', values: [[5,3], [4,2], [3,0], [2,0], [1,0]], colorIndex: "graph-2"}
];
推荐答案
已将拉取请求合并到 React 存储库,以便在再次发生此类错误时为开发人员提供更好的反馈.
A pull request has been merged to the React repo that provides a better feedback for the developer whenever a mistake like this happens again.
现在,验证消息将如下所示:
Now, the validation message will look like the following:
提供给 oneOf 的参数无效,需要一个数组实例.
Invalid argument supplied to oneOf, expected an instance of array.
https://github.com/facebook/react/pull/3963
这应该是 React 0.14 的一部分.
This should be part of React 0.14.
这篇关于反应:检查器不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!