我收到以下错误.我可以看到我必须返回数组而不是对象.但我真的不确定如何解决它.提前致谢
对象作为React子对象无效.如果您要渲染子集合,请使用数组,或使用React附加组件中的createFragment(object)包装对象.检查渲染方法
View.
constructor(props){
super(props);
this.state = {timeElapsed: null};
}
startStopButton(){
return <TouchableHighlight underlayColor="gray" onPress={this.handleStartPress.bind(this)}>
<Text>Start</Text>
</TouchableHighlight>
}
handleStartPress(){
var startTime = new Date();
setInterval(()=>{
this.setState({timeElapsed: new Date()})
}, 1000);
}
render(){
return(
<View style={styles.container}>
<View style={[styles.header]}>
<View style={[styles.timerContainer, this.borderColor('#ff6666')]}>
{this.state.timeElapsed}
</View>
<View style={[styles.buttonsContainer, this.borderColor('#558000')]}>
{this.startStopButton()}
{this.lapButton()}
</View>
</View>
</View>
);
}
Run Code Online (Sandbox Code Playgroud) react-native ×1