2017-07-17 45 views
0

我想要做的是在我的應用程序中放置一個側欄,但是I'm getting this weird error爲什麼我在iOS模擬器中出現這個奇怪的錯誤?

對象是不是一個做出反應的孩子有效(發現: 對象與鍵(彎曲,的backgroundColor})如果 你的意思是使孩子們的集合, 使用不是數組
英寸。視圖(在Animatedlmplementation.js: 184q)
   在AnimatedComponent(在SidebarView.js 210)
 在RCTView  (在View.js:133)
   在視圖(在SidebarView.js:2O3)
在SidebarView    (在index.ios.js:48)
 在酒吧 (在index.ios.js:65)
   在提供商(在index.ios.js:6Q)
 在DAPP  (在renderApplication.js:35)
 在RCTView  (在View.js:133)
 在View  (在AppContainer.js :98)
在RCTView    (在View.js:133)
 在查看 (在AppContainer.js:97)

我得到了react-redux<Provider/>組件預計其子道具是一個單一的ReactElement因此爲什麼我將所有內容都包含在一個名爲<Bar/>的組件中。

這裏是我的代碼:

import React, { Component } from 'react'; 
import { AppRegistry, Text} from 'react-native'; 
import { Provider } from 'react-redux'; 
import Application from './pages/Application'; 
import store from './redux'; 
import api from './utilities/api'; 
import SideBar from 'react-native-sidebar'; 

export default class DApp extends Component { 
    constructor(props) { 
     super(props); 
     this.state = { 
      data: [], 
      isLoading: true 
     } 
     console.log("something"); 
    } 

    componentWillMount() { 
     api.getData().then((res) => { 
      this.setState({ 
       data: res.data 
      }) 
     }); 
    } 

    renderLeftSideBar() { 
     return(
      <Text>Something here for left side bar!</Text> 
     ); 
    } 

    renderRightSideBar() { 
     return(
      <Text>Something here for right side bar!</Text> 
     ); 
    } 

    renderContent() { 
     return(
      <Text>The content!</Text> 
     ); 
    } 

    render() { 
     const Bar =() => { 
      return(
       <SideBar> 
        leftSideBar = {this.renderLeftSideBar()} 
        rightSideBar = {this.renderRightSideBar()} 
        style = {{flex: 1, backgroundColor: 'black'}}>{this.renderContent()} 
        <Application/> 
       </SideBar> 
      ); 
     } 

     if(this.state.isLoading) { 
      console.log("The data is: " + this.state.data); 
     } else { 
      console.log("Else got executed"); 
     } 

     return (
      <Provider store={store}> 
       <Bar/> 
      </Provider> 
     ); 
    } 
} 

AppRegistry.registerComponent('DApp',() => DApp); 
+0

leftSideBar = {this.renderLeftSideBar()} rightSideBar = {this.renderRightSideBar()} 風格= {{柔性:1的backgroundColor: '黑'}}> {此。renderContent()} <應用程序/> 看起來像這個屬性應該已經喂入邊欄 –

回答

1

它看起來對我來說,有一個在你的代碼中的錯字 - leftSideBarrightSideBarstyle屬性不與<SideBar>相關的,因爲你有一個額外> - 我認爲,如果你只是使用

 return(
      <SideBar 
       leftSideBar = {this.renderLeftSideBar()} 
       rightSideBar = {this.renderRightSideBar()} 
       style = {{flex: 1, backgroundColor: 'black'}}>{this.renderContent()} 
       <Application/> 
      </SideBar> 
     ); 

你可能是好的

+0

謝謝!這對我有效。 –

+0

太棒了,很高興我能幫上忙。 – skwidbreth

1

leftSideBar,rightSideBar和風格應該是側欄組件的道具,像這樣:

<SideBar leftSideBar = {this.renderLeftSideBar()} rightSideBar = {this.renderRightSideBar()} style = {{flex: 1, backgroundColor: 'black'}}>{this.renderContent()} 
       <Application/> 
      </SideBar> 
相關問題