当前位置:首页 > 开发 > 软件应用 > 正文

React Uncaught Invariant Violation: onlyChild must be passed a children with exa

发表于: 2016-05-14   作者:qiaolevip   来源:转载   浏览:
摘要: 报错提示: UncaughtInvariantViolation:onlyChildmustbepassedachildrenwithexactlyonechild.  报错代码: pmessage=this.state.showmessage?{this.state.pmessage}:""; return( {pmessage} );  解决方案:pmessage=t

报错提示:

 

Uncaught Invariant Violation: onlyChild must be passed a children with exactly one child.

 

 

报错代码:

 

pmessage = this.state.showmessage?<div className="pmessage">{this.state.pmessage}</div>:"";

return (
      <div className="userinfo">
        <TimeoutTransitionGroup enterTimeout={450} leaveTimeout={450} transitionName="pmessage" className='pmessage' >
          { pmessage }
        </TimeoutTransitionGroup>
      </div>
    );

 

 

解决方案:

pmessage = this.state.showmessage?<div className="pmessage">{this.state.pmessage}</div>:<div></div>; // 添加child DOM


return (
      <div className="userinfo">
        <TimeoutTransitionGroup enterTimeout={450} leaveTimeout={450} transitionName="pmessage" className='pmessage' >
          { pmessage }
        </TimeoutTransitionGroup>
      </div>
    );

 



有疑问或技术交流,扫描公众号一起讨论学习。

更多React在线学习访问:http://each.sinaapp.com/react/index.html

React Uncaught Invariant Violation: onlyChild must be passed a children with exa_第1张图片

React Uncaught Invariant Violation: onlyChild must be passed a children with exa

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号