渲染功能不适用于侧边栏

时间:2017-07-17 01:16:36

标签: javascript ios reactjs react-native

我正在关注https://www.npmjs.com/package/react-native-sidebar以实施侧边栏。刷新iOS模拟器后I'm getting this error。我按原样按照说明进行操作,但在我的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);

1 个答案:

答案 0 :(得分:0)

你的班级DApp没有函数renderLeftSideBar();这就是你的函数是unresolved

的原因

要解决此问题,您需要创建一个函数renderLeftSideBar(),它返回左侧栏的内容。阅读您链接的文档会显示leftSideBar的类型为Component。

  

leftSidebar:Compontent

通常,我会在render()上面定义函数。

renderLeftSideBar() {
    return <div>
        (content goes here)
    </div>
}
相关问题