gpt4 book ai didi

javascript - 对象作为 React 子对象无效(在 React 15.4.1 的 Internet Explorer 11 中)

转载 作者:行者123 更新时间:2023-12-03 13:02:35 24 4
gpt4 key购买 nike

Objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props, _owner, _store}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of App.

应用程序容器:

const mapDispatchToProps = (dispatch) => {
return {

}
}
}
}

组件:

class App extends Component {
render() {
return (
);
}
}

上面是我的 app.js 渲染函数。此代码在 google chrome 中工作正常,但是当进入 Internet explorer 时它不起作用,并且抛出上述错误。

最佳答案

自 React 15.4 和 IE11 以来出现的问题

如果您仍然遇到此问题,您可以查看this react issue #8379 about React 15.4 and IE11 。我在 webpack 开发模式/IE11/React 15.4 中遇到了同样的问题,似乎 React 和 ReactDom 都使用了各自版本的 Symbol polyfill(这是 15.4 中的新功能):

Somehow react and react-dom no longer "agree" on the $$typeof value

which should be typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103.

解决方案

我通过重新排序polyfillreact/react-dom解决了这个问题,以确保polyfill符号在React之前加载和 ReactDom 的 Symbol...现在他们“同意”$$typeof 值。

Webpack 的示例解决方案:

entry: [
'babel-polyfill', // Load this first
'react-hot-loader/patch', // This package already requires/loads react (but not react-dom). It must be loaded after babel-polyfill to ensure both react and react-dom use the same Symbol.
'react', // Include this to enforce order
'react-dom', // Include this to enforce order
'./index.js' // Path to your app's entry file
]

关于javascript - 对象作为 React 子对象无效(在 React 15.4.1 的 Internet Explorer 11 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40897966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com