gpt4 book ai didi

reactjs - PropTypes.exact 和 PropTypes.shape 之间的区别

转载 作者:行者123 更新时间:2023-12-03 14:02:31 24 4
gpt4 key购买 nike

有什么区别

PropTypes.exact({
name: PropTypes.string,
age: PropTypes.number
})

对比

PropTypes.shape({
name: PropTypes.string,
age: PropTypes.number
})

我会很高兴得到任何帮助

最佳答案

基本上,如果您的 prop 对象包含通过 PropTypes.exact({ }) 声明时未提及的额外属性,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

关于reactjs - PropTypes.exact 和 PropTypes.shape 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59019287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com