【问题标题】:IE11: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: objectIE11:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:对象
【发布时间】:2019-04-03 21:34:37
【问题描述】:
const header = ReactDOMServer.renderToString(<MyComponent testprops={this.props.testprops}  />)

我收到“元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但得到:对象。”仅在 Internet Explorer 11 中发布。

当我删除上面的代码时,它工作得很好,我需要带有标题的 window.print() 的 abpve 代码

修复:

const MyComponent = React.memo(props => {
   return (<span>Testing</span>)
})

改为

class MyComponent extends PureComponent {
    return (<span>Testing</span>)
}

React.memo 抛出错误

【问题讨论】:

  • 你能粘贴MyComponent的代码
  • 它是一个 React.memo 导出的,我改成它工作的功能组件
  • 从您上次的评论来看,您的问题似乎已解决。我建议您将您的解决方案作为答案发布,并尝试在 48 小时后将您自己的答案标记为该问题的可接受答案,此时可以标记。它可以在未来帮助其他社区成员解决类似的问题。感谢您的理解。

标签: reactjs internet-explorer-11


【解决方案1】:
ReactDOMServer.renderToString(<MyComp />)

MyComp 不应使用 React.memo&lt;Fragment&gt; 构造,IE11 会抛出 Element type is invalid 错误。

删除React.memo&lt;Fragment&gt; 将解决问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 2020-03-07
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    相关资源
    最近更新 更多