之间有什么区别
PropTypes.exact({
name: PropTypes.string,
age: PropTypes.number
})
vs
PropTypes.shape({
name: PropTypes.string,
age: PropTypes.number
})
我将很高兴得到任何帮助
如果您的prop对象包含通过exact
进行声明时未提及的额外属性,则基本上PropTypes.exact({ })
会向您发出警告。
// An object taking on a particular shape
optionalObjectWithShape: PropTypes.shape({
color: PropTypes.string,
fontSize: PropTypes.number
}),
// An object with warnings on extra properties
optionalObjectWithStrictShape: PropTypes.exact({
name: PropTypes.string,
quantity: PropTypes.number
}),
参考:https://reactjs.org/docs/typechecking-with-proptypes.html#proptypes