【发布时间】:2019-01-28 17:29:13
【问题描述】:
class ContentLoader extends Component {
state = {
animation: new Animated.Value(0)
}
render() {
if (this.props.loading) {
return (<View
style={{
height: 100,
width: 100
}}
/>);
}
return this.props.children;
}
}
ContentLoader.prototype = {
primaryColor: PropTypes.string,
secondaryColor: PropTypes.string,
animationDuration: PropTypes.number,
// children: PropTypes.element.isRequired,
style: PropTypes.object.isRequired,
loading: PropTypes.bool,
}
ContentLoader.defaultProps = {
primaryColor: 'rgba(195, 191, 191, 1)',
secondaryColor: 'rgba(218, 215, 215, 1)',
animationDuration: 500,
loading: true
};
export default ContentLoader;
当我在我的组件中使用它时,我得到没有从渲染返回任何内容? 但是当我评论这部分时
ContentLoader.prototype = {
primaryColor: PropTypes.string,
secondaryColor: PropTypes.string,
animationDuration: PropTypes.number,
// children: PropTypes.element.isRequired,
style: PropTypes.object.isRequired,
loading: PropTypes.bool,
}
一切正常? 有什么帮助吗? 没有道具类型,一切都很好,或者我做错了什么。
【问题讨论】:
-
您能展示一下您是如何使用它的吗?
-
你应该设置的属性是
propTypes而不是prototype,这是完全不同的东西。 -
我都试过了,还是一样的错误
-
@JoeWarner 我把它修剪成只有 render() { return
hi },但还是一样,当我取消注释该 propTypes 时,一切正常 -
@SarmadAijaz 是的,这是 trinx 所说的
标签: javascript reactjs react-native