2017-08-02 26 views
0

對象作爲React子項無效。如果您打算渲染一組兒童,請改用數組,或者使用React附加組件中的createFragment(object)來包裝對象。檢查Root的渲染方法。「對象作爲React子項無效」僅在IE中出現

這一問題只出現在IE瀏覽器,我知道一個孩子的反應不能是一個對象,但我不能找到根類的任何錯誤

// Root.js 
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) 

    return (
     <Provider store={store}> 
     <div> 
      <Router history={history} routes={routes} /> 
     </div> 
     </Provider> 
    ) 
    } 
} 



// routes.js 

import React from 'react' 
import { Route } from 'react-router' 

import Cookie from './libs/cookie' 
import App from './app' 
import MobileRouter from './routes/mobile' 
import WebRouter from './routes/web' 

export default (
    <Route path="/" component={App}> 
    { WebRouter } 
    { MobileRouter } 
    </Route> 
) 



// App.js 

import React, { Component, PropTypes } from 'react' 
import { connect } from 'react-redux' 
import { browserHistory } from 'react-router' 

class App extends Component { 
    constructor(props) { 
    super(props) 
    } 

    render() { 
    const { children } = this.props 

    return (
     <div> 
     { children } 
     </div> 
    ) 
    } 
} 
+0

請顯示'routes'組件。 – Andrew

+0

我已添加路由添加應用組件代碼 –

+0

我認爲問題在這裏,{WebRouter} {MobileRouter}'。什麼是「MobileRouter」和「WebRouter」? – Andrew

回答

0

「的對象是不能作爲有效反應子「只出現在IE中

不正確。如果您使用對象,則此錯誤將出現在所有瀏覽器中。你最有可能有類似於下面的東西在你的代碼

{someBool && someObj} 

其中someBool僅現身真正基於應用程序的狀態是如何在IE瀏覽器。如果您在任何其他瀏覽器中執行了相同的操作,您將得到相同的錯誤。

修復

不要渲染object。 React無法處理它。並且正在給你正確的錯誤,你應該修復它,例如從obj中渲染一些東西,例如

{someBool && someObj.someStringProp} 
相關問題