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 ); </> } }