pat*_*man 11 react-native react-proptypes
我有一个结构简单的组件和<Text>树内的某个地方,我希望以一种风格传递.这对于proptypes验证非常有效.
基本设置不仅仅是这个
export default class Component extends PureComponent {
render() {
return (<View><Text style={this.props.style}>Some text</Text></view>);
}
}
Component.defaultProps = {
style: null,
};
Component.propTypes = {
style: ViewPropTypes.style,
};
Run Code Online (Sandbox Code Playgroud)
问题是ViewPropTypes.style不包含ie color键.因此,提供带有颜色的样式无效并产生警告.我试图导入,TextStylePropTypes如我在https://github.com/facebook/react-native/blob/master/Libraries/Text/TextStylePropTypes.js中找到的,但它是未定义的.
关于该怎么做的任何建议?
由于传递的样式道具用于文本节点,请使用Text.propTypes.style如下所示...
Component.propTypes = {
style: Text.propTypes.style
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3062 次 |
| 最近记录: |