【发布时间】:2018-05-07 00:43:54
【问题描述】:
这是我产生的代码
警告:LoaderView(...): 当在
LoaderView中调用 super() 时,使 确保传递与组件的构造函数相同的道具 通过了。
import * as React from "react";
import {ActivityIndicator, Text, View} from 'react-native'
export class LoaderView extends React.Component {
constructor(props) {
super(props)
}
props = {
title: "",
loading: false
}
render() {
if (this.props.loading) {
return <View {...this.props} style={{flex: 1, justifyContent: 'center'}}>
<ActivityIndicator
size={"large"}
animating={true}/>
<Text
style={{textAlign: 'center', fontSize: 20, fontWeight: '500'}}>
{this.props.title}
</Text>
</View>
} else {
return <View {...this.props} style={{flex: 1, justifyContent: 'center'}}>
<Text
style={{textAlign: 'center', fontSize: 20, fontWeight: '500'}}>
{this.props.title}
</Text>
</View>
}
}
}
如何解决上述代码中的这个警告?
【问题讨论】:
-
尝试静态 defaultProps = { title: "", loading: false };而不是 props = { ... }
标签: javascript reactjs react-native ecmascript-6