React使用portal提示 The types returned by 'render()' are incompatible between these types.  Type 'ReactPortal' is not assignable to type 'ReactNode'.   Type '{}' is not assignable to type 'ReactNode'.

原因:组件返回了个不是<></>的东西

原先代码:

export default class Index extends React.PureComponent {
  render() {
    return reactDOM.createPortal(
      <div>传送内容</div>,
      document.body
    );
  }
}

结局方案:

export default class Index extends React.PureComponent {
  render() {
    return <>
      reactDOM.createPortal(
      <div>传送内容</div>,
      document.body
      );
    </>
  }
}

  

 

posted @ 2022-07-30 18:35  PromiseOne  阅读(806)  评论(0编辑  收藏  举报