PropTypes 和 DefaultProps
import PropTypes from 'prop-types';
//对组件属性进行强校验
TodoListItem.propType = {
content: PropTypes.string, //content必须是String类型
handleItemDel:PropTypes.func,//handleItemDel必须是一个方法
index:PropTypes.number,
test:PropTypes.string.isRequired,//类型string并且必须传值
}
TodoListItem.defaultProps ={
test:‘hello world’,//当父组件没有传值时候默认一个
}