IE下报错“Objects are not valid as a React child”

错误描述:Objects are not valid as a React child. 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 Root.

我知道react child不能是一个对象,需转成数组或者字符串 ,但是我没在我的Root类里发现这样的错误,而且这个bug只在IE下出现,这个错误信息是指Root类本身有问题还是说Root类里所有可能渲染的组件有问题

import React, { Component, PropTypes } from 'react'
import { Provider } from 'react-redux'
import { Router, browserHistory } from 'react-router'
import { syncHistoryWithStore } from 'react-router-redux'
import routes from './routes'

export default class Root extends Component {
  render() {
    const { store } = this.props
    const history = syncHistoryWithStore(browserHistory, store)
        // render Root, and Router, which will load specific component when an URL is loaded
    return (
      <Provider store={store}>
        <div>
          <Router history={history} routes={routes} />
        </div>
      </Provider>
    )
  }
}```
阅读 5.7k
2 个回答

在入口文件前加入了babel-polyfill
参考:https://github.com/facebook/r...

entry: {
    'app': ["babel-polyfill", "./webpack/javascripts/react/index.js"]
}```

可能是使用了 IE 不支持的语法或者函数,导致最后的结果不是一个函数(React 组件都是函数)而是一个对象。

断点跟一下吧。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题