`createPortal` 属性在类型中缺少 ‘children’,但在类型 ‘ReactPortal’ 中是必需的。

huangapple go评论74阅读模式
英文:

createPortal Property 'children' is missing in type but required in type 'ReactPortal'

问题

我正在尝试将一个元素传送到 document.body,但 TypeScript 报告了以下错误:

Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'.

我该如何修复这个 createPortal 类型错误?

`createPortal` 属性在类型中缺少 ‘children’,但在类型 ‘ReactPortal’ 中是必需的。

即使使用像 &lt;p&gt; 这样的原生 HTML 元素也不起作用,如下所示。

`createPortal` 属性在类型中缺少 ‘children’,但在类型 ‘ReactPortal’ 中是必需的。

英文:

I'm trying to portal out an element to document.body but typescript claims

Property &#39;children&#39; is missing in type &#39;ReactElement&lt;any, string | JSXElementConstructor&lt;any&gt;&gt;&#39; but required in type &#39;ReactPortal&#39;.

How can I fix this createPortal typing error?

`createPortal` 属性在类型中缺少 ‘children’,但在类型 ‘ReactPortal’ 中是必需的。

It also does not work even with a native HTML element like &lt;p&gt; as shown below.

`createPortal` 属性在类型中缺少 ‘children’,但在类型 ‘ReactPortal’ 中是必需的。

答案1

得分: 0

createPortal 在 NextJS 组件中不起作用。

英文:

createPortal does not work in NextJS components

huangapple
  • 本文由 发表于 2023年8月4日 06:45:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76832000.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定