react-native – 对象作为React子对象无效

前端之家收集整理的这篇文章主要介绍了react-native – 对象作为React子对象无效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我收到以下错误.我可以看到我必须返回数组而不是对象.但我真的不确定如何解决它.提前致谢

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) from the React add-ons. Check the render method
of 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>
);


}
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>

猜你在找的React相关文章