自定义类型检查。

This commit is contained in:
tengge1 2019-05-31 22:19:13 +08:00
parent 66f6dad21d
commit e5b22fbfc9

View File

@ -36,7 +36,12 @@ class DataGrid extends React.Component {
DataGrid.propTypes = {
className: PropTypes.string,
style: PropTypes.object,
children: PropTypes.instanceOf(Columns),
children: (props, propName, componentName) => {
const children = props[propName];
if (children.type !== Columns) {
return new TypeError(`Invalid prop \`${propName}\` of type \`${children.type.name}\` supplied to \`${componentName}\`, expected \`Columns\`.`);
}
},
data: PropTypes.array,
};