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

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

你可能感兴趣的:(每天进步一点点,众观千象,学习永无止境,react,乔乐共享)