我有 index.html
<body>
<div id="portal"></div>
<div id="root"></div>
</body>
并希望使用低于单独的组件portal div
比root div
,
import React from 'react';
const portalDiv = document.getElementById('portal');
function Portal1(props) {
return ReactDOM.createPortal(
<div>
{props.children}
<div/>,
portalDiv); //here
}
export default Portal1;
但我收到此错误,类型为“HTMLElement |的参数” null' 不可分配给类型为 'Element' 的参数。类型 'null'在 VScode 中不能分配给类型 'Element'.ts(2345)。
我正在使用typescript。请帮忙。