2 回答
![?](http://img1.sycdn.imooc.com/545861b80001d27c02200220-100-100.jpg)
TA贡献1860条经验 获得超9个赞
您误解了 的类型children并混淆了使用defaultProps:
// Use for initial value
CartProvider.defaultProps = {
counter: 10,
/*
You declared the initial value to be the value of `PropTypes.string`
children: PropTypes.string
*/
}
// Children are always an Array of `ReactElement`/ `ReactElement` node.
CartProvider.propTypes = {
counter: PropTypes.number,
children: PropTypes.node.isRequired,
/* Same
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node
]).isRequired
*/
/*
props.children can't be a string.
children: PropTypes.string,
*/
}
![?](http://img1.sycdn.imooc.com/5333a1920001d36402200220-100-100.jpg)
TA贡献1859条经验 获得超6个赞
defaultProps 应该设置一个值而不是再次使用 Proptypes
CartProvider.propTypes = {
children: PropTypes.string,
}
CartProvider.defaultProps = {
children: "This is chidlren default string"
}
添加回答
举报