React linter airbnb proptypes array React linter airbnb proptypes array reactjs reactjs

React linter airbnb proptypes array


A possible solution for this (but I think it is not smart):

SmartTable.propTypes = {  name: React.PropTypes.string.isRequired,  cols: React.PropTypes.arrayOf(React.PropTypes.string),  rows: React.PropTypes.arrayOf(React.PropTypes.string),};


One of the solution which worked for me:

If you want arrays:

SmartTable.propTypes = {  name: PropTypes.string.isRequired,  cols: PropTypes.instanceOf(Array),  rows: PropTypes.instanceOf(Array),};

For Objects and Arrays, It can be:

SmartTable.propTypes = {  name: PropTypes.string.isRequired,  cols: PropTypes.instanceOf(Object),  rows: PropTypes.instanceOf(Array),};


If the array of cols and rows are objects I like using shape so it could be something like this.

    SmartTable.propTypes = {      name: PropTypes.string.isRequired,      cols: PropTypes.arrayOf(PropTypes.shape({        id: PropTypes.string.isRequired,        value: PropTypes.string,       })      rows: PropTypes.arrayOf(PropTypes.shape({        id: PropTypes.string.isRequired,        value: PropTypes.string,       })};