2017-07-17 76 views
0

我正在關注https://www.npmjs.com/package/react-native-sidebar以實施側邊欄。 I'm getting this error刷新我的iOS模擬器。我按照現在的方向,但在我的WebStorm IDE這是說Unresolved function or method renderLeftSideBar()Unresolved function or method renderLeftSideBar()渲染功能將無法用於側邊欄

下面的代碼:

import React, { Component } from 'react'; 
import { AppRegistry} 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>Someting here for left side bar!</Text> 
    ); 
} 

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

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

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

     return (

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

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

定義'renderLeftSideBar','renderRightSideBar'和'renderContent'功能 –

+0

要搞清楚的事情瞭解'this'關鍵字在JavaScript中,同時使用'class'關鍵字如何做到這一點的行爲。 –

回答

0

你的類DAPP不具備的功能renderLeftSideBar();這就是爲什麼你的功能是unresolved

要解決此問題,您需要創建一個函數renderLeftSideBar(),該函數返回左側欄的內容。閱讀鏈接的文檔顯示,leftSideBar是Component類型。

leftSidebar:Compontent

通常,我將定義上述render()的功能。

renderLeftSideBar() { 
    return <div> 
     (content goes here) 
    </div> 
} 
+0

好的,我定義了所有這些(我在原始文章中更改了我的代碼),但是現在它給了我一個錯誤,說'React,孩子只希望接收一個React元素子元素。 –

+0

這個答案有幫助嗎? https://stackoverflow.com/questions/43300897/react-children-only-expected-to-receive-a-single-react-element-child-navigator – Schomes

+0

也許是因爲你有兩個SideBar和應用嵌套在內。 – Schomes