2017-07-17 6 views
0

私がしようとしているのは、アプリにサイドバーを置くことですが、I'm getting this weird errorです。 。iOSシミュレータでこの奇妙なエラーが発生するのはなぜですか?

オブジェクトが見つかりました(リアクト子として有効ではありません:キーを持つ オブジェクト(フレックス、backgroundColorのを})あなたが子供のコレクションをレンダリングするためのもの 場合、 ではなく配列を使用
   に(Animatedlmplementation.jsで: 184q)図
    AnimatedComponentでRCTViewで
   (SidebarView.js 210で)(View.js時:133)
(index.ios.js時:48)SidebarViewで    バーで
   (index.ios.js時:65)
   中:(2O3 SidebarView.jsで)ビューで    AppContainer.jsのビューで:(133 View.jsで)
   (RCTViewで
   :(35 renderApplication.jsで)DAPPで
   :(6Q index.ios.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

それはあなたのコードにタイプミスがありますように私には見えます - leftSideBarは、rightSideBar、そしてあなたは、余分な>を持っているので、style属性は、<SideBar>に関連付けられていない - 私は考えていることあなただけ

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

を使用した場合、あなたはおそらく良いだろう

+0

ありがとうございました!これは私のために働いた。 –

+0

偉大な、私は助けることがうれしいです。 – skwidbreth

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

バー・コンポーネントの定義が有効JSXを返しません:leftSideBar、rightSideBarとスタイルは、このように、サイドバーコンポーネントの小道具でなければなりません。

import { your other components ..., View } from 'react-native'; 

<SideBar> 
    {this.renderLeftSideBar()} 
    {this.renderRightSideBar()} 
    <View style = {{flex: 1, backgroundColor: 'black'}}> 
    {this.renderContent()} 
    </View> 
    <Application/> 
</SideBar> 
関連する問題