react-native – 对象作为React子对象无效
发布时间:2020-12-15 20:55:00 所属栏目:百科 来源:网络整理
导读:我收到以下错误.我可以看到我必须返回数组而不是对象.但我真的不确定如何解决它.提前致谢 Objects are not valid as a React child. If you meant to render a collection of children,use an array instead or wrap the object using createFragment(object
我收到以下错误.我可以看到我必须返回数组而不是对象.但我真的不确定如何解决它.提前致谢
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> ); }
timeElapsed是一个对象,React不知道如何呈现这个:
<View style={[styles.timerContainer,this.borderColor('#ff6666')]}> {this.state.timeElapsed} </View> 尝试更改this.state.timeElapsed以获取字符串,例如: <View style={[styles.timerContainer,this.borderColor('#ff6666')]}> {this.state.timeElapsed.toString()} </View> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |