I am new to react. I wrote following code to define the PropTypes of my component:
ListViewer.propTypes = {
dataRows: PropTypes.oneOf([PropTypes.object, PropTypes.array]).isRequired,
columnHeaders: PropTypes.object.isRequired,
headerColumn: PropTypes.string.isRequired,
onRowPress: PropTypes.func.isRequired,
}
And I called my component like following:
const items= [{
name: "Iodine",
price: 33,
amount: 11
},
{
name: "Chlorine",
price: 23,
amount: 1
}];
.....
.....
<ListViewer dataRows={items} columnHeaders={headers} headerColumn="name" onRowPress={this.onRowPress}/>
.....
I got following warning:
Warning: Failed prop type: Invalid prop `dataRows` of value `[object Object]` supplied to `ListViewer`, expected one of [null,null].
in ListViewer (at AvailableItems.js:53)
in AvailableItems (at SceneView.tsx:122)
in StaticContainer
in StaticContainer (at SceneView.tsx:115)
......
I changed the Proptype of dataRows to array, I get following warning:
Warning: Failed prop type: Invalid prop `dataRows` of type `object` supplied to `ListViewer`, expected `array`
And for type of object I get a similar warning. Could you please tell me what am I doing wrong and how can I fix it? Thanks in advance.