[英]How to set PropType for an objectOf either strings or functions?
I have a prop which is an object of strings and functions.我有一个道具,它是字符串和函数的 object。 I attempted to set proptypes as
我试图将 proptypes 设置为
component.propTypes = {
propName: PropTypes.objectOf(PropTypes.oneOf([PropTypes.string, PropTypes.func])
}
However that doesn't seem to work as I'm getting and error saying that it reads the inside parameter as '[object Object]'.但是,这似乎不起作用,因为我得到并且错误说它将内部参数读取为'[object Object]'。 How can define the prop as an object of either string or function?
如何将道具定义为字符串或 function 的 object?
TMI. TMI。 This is for Material UI's sx prop, and I'm not using TypeScript in my project
这是用于 Material UI 的 sx 道具,我没有在我的项目中使用 TypeScript
I use sx
and in my definitions it's just an object.我使用
sx
,在我的定义中它只是一个 object。
component.propTypes = {
propName: PropTypes.object
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.