`

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

阅读更多

报错提示:

 

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


更多实例应用扫码体验:

分享到:
评论
1 楼 softor 2018-01-04  
这个结论有木有权威的依据?

相关推荐

Global site tag (gtag.js) - Google Analytics