如何在propTypes中声明样式? [英] How to declare style in propTypes?
本文介绍了如何在propTypes中声明样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 forbid-启用了prop-type 规则, eslint
禁止我使用样式:React.PropTypes.object
和建议使用 shape
。
With the forbid-prop-types rule enabled, eslint
forbids me from using style: React.PropTypes.object
, and using shape
is suggested.
但是是否真的有必要为此定义所有可用属性? ?
But is it really necessary to define all the available properties there for this purpose like this?
DEMO.propTypes = {
style: React.PropTypes.shape({
color: React.PropTypes.string,
fontSize: React.PropTypes.number,
...
})
};
定义代码太多!
推荐答案
React Native现在包含 ViewPropTypes
,它将替换 View.propTypes.style
。用法示例:
React Native now contains ViewPropTypes
, which will replace View.propTypes.style
. Example of usage:
import { ViewPropTypes } from 'react-native';
MyComponent.propTypes = {
style: ViewPropTypes.style
};
这篇关于如何在propTypes中声明样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文