[英]Warning: Failed propType: Invalid prop of type `array` expected `object` with React
So this line of code is throwing something like ' Failed propType: Invalid prop of type array
expected object
.' 因此,这行代码抛出的内容类似于“Failed propType:类型
array
预期object
无效prop”。
Why is this happening? 为什么会这样?
Here is my JSON: 这是我的JSON:
"student_records": [
{
"program": "PSCI-210",
"grade": 80
}
]
jsx: JSX:
import React, { PropTypes } from 'react';
const StudentRecordPropTypes = {
studentRecordData: PropTypes.object.isRequired,
};
function StudentRecord(props) {
const Records = props.studentRecordData;
return (
<div>
{(Records || []).map(student_records => (
<ul>
<li>{student_records.program} : {student_records.grade} </li>
</ul>
))}
</div>
);
}
StudentRecord.propTypes = StudentRecordPropTypes;
export default StudentRecord;
It displays correctly. 它显示正确。 After some googling, I realized that its looking to an array but its infact an object.
经过一些谷歌搜索,我意识到它寻找一个数组,但它实际上是一个对象。 My problem is that I don't know how to fix it.
我的问题是我不知道如何解决它。 How can I remove this error?
如何删除此错误?
Change 更改
const StudentRecordPropTypes = {
studentRecordData: PropTypes.object.isRequired,
};
to 至
const StudentRecordPropTypes = {
studentRecordData: PropTypes.array.isRequired,
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.