react里报这个错误该怎么解决呢?

代码:

funcOne = props => {

    let {
      time,
      minTechnics,
      isNProcessOffer,
      isNSampleOffer,
      processTadeAttributes,
      unit,
    } = props;
    if (isNProcessOffer) {

      let { sampleTime, reserveRange, minReserveAmount } = processTadeAttributes;
      if (isNSampleOffer) {

        return (<div className="time clearfix"><div className="printNum">支持</div> <div className="time">周期{sampleTime}天</div></div>);
      }
      let result = reserveRange.filter(item => item.beginAmount === minReserveAmount);
      return (<div  className="time clearfix"><div className="printNum">订量:{minReserveAmount}{unit}</div>  <div className="time">时间:{result[0].date} 天</div></div>);
    }

    return (<div  className="time clearfix"><div className="printNum">订量:{minTechnics}{unit}</div> <div className="time">周期:{time} 天</div></div>);
  };
render(){
     return (
        <div>
          {
              this.props.data.map((v,index)=>{
                     return (
                          <div>
                               {
                                   this.funcOne(v)
                               }
                          </div>
                     )
              })
          }
        </div>  
     )
}

控制台错误提示:

Uncaught Error: Objects are not valid as a React child (found: object with keys {default, spot_qt_sy}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React

阅读 3.3k
3 个回答
render(){
     return (
     
          {// 去掉
              this.props.data.map((v,index)=>{
                     return (
                          <div>
                               {
                                   this.funcOne(v)
                               }
                          </div>
                     )
              })
          }// 去掉
     )
}

这个map循环外面需要套一层,因为render规定只能是单个组件

render(){
     return (
         <div>//加一层
          {
              this.props.data.map((v,index)=>{
                     return (
                          <div>
                               {
                                   this.funcOne(v)
                               }
                          </div>
                     )
              })
          }
         </div>
     )
}
render(){
     return (
              this.props.data.map((v,index)=>{
                     return (
                          <div>
                               {
                                   this.funcOne(v)
                               }
                          </div>
                     )
              })
     )
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题