1.对父组件传入的属性进行类型校验
import PropTypes from 'prop-types'
//组建外面
TodoItem.propTypes = {
//父组件必须传入
test:PropTypes.string.isRequired,
content : PropTypes.string.isRequired,
index: PropTypes.number.isRequired,
handleItemDelete: PropTypes.func.isRequired
}
TodoItem.defaultProps = {
//默认属性
test:'helloworld'
}
类型不对会报错
index.js:2178 Warning: Failed prop type: Invalid prop `content` of type `number` supplied to `TodoItem`, expected `string`.