So this line of code throws something like 'Failed propType: Invalid prop of type arrayexpected object.'
Why is this happening?
Here is my JSON:
"student_records": [
{
"program": "PSCI-210",
"grade": 80
}
]
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 is displayed correctly. After some googling, I realized that it was looking at an array, but its infact object. My problem is that I do not know how to fix it. How to remove this error?
source
share