So this line of code is throwing something like ' Failed propType: Invalid prop of type array
expected 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 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,
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With