React Native - 渲染中没有返回任何内容

时间:2018-01-30 11:25:03

标签: react-native react-redux react-navigation

我的应用程序存储在/src/index.js中,但我也有/App.js和/index.js。

我不知道这些之间的区别,我认为这是导致此错误的原因。

enter image description here

/index.js

import { AppRegistry } from 'react-native';
import App from './App';
AppRegistry.registerComponent('client', () => App);

/App.js

import App from './src/index';

export default App;

/src/index.js

import React from 'react';
import { AppRegistry } from 'react-native';
import { Provider, connect } from 'react-redux';
import { addNavigationHelpers } from 'react-navigation';

import Navigator from './routes/route';
import store from './store/configureStore';


const App = ({ dispatch, nav }) => {

    <Navigator
        navigation={addNavigationHelpers({
            dispatch,
            state: nav,
        })}
    />
};

const mapStateToProps = state => ({
    nav: state.nav,
});



const AppWithNavigation = connect(mapStateToProps)(App);

export default () => {

    <Provider store={store}>
        <AppWithNavigation />
    </Provider>

}

我使用create react native package来构建这个项目,然后尝试按照一些指南来实现与redux的反应导航。

2 个答案:

答案 0 :(得分:7)

您的默认导出未返回任何内容:

export default () => {

    <Provider store={store}>
        <AppWithNavigation />
    </Provider>

}

要使用箭头函数返回JSX,您需要使用() => ( <JSX /> )或大括号的等效项:() => { return ( <JSX /> ) }

export default () => (    
    <Provider store={store}>
        <AppWithNavigation />
    </Provider>
)

或:

export default () => {
    return (    
       <Provider store={store}>
           <AppWithNavigation />
       </Provider>
   )
}

答案 1 :(得分:2)

您忘了return components

const App = ({ dispatch, nav }) => {
    return(
        <Navigator
            navigation={addNavigationHelpers({
                dispatch,
                state: nav,
            })}
        />
    )
};


export default () => {
    return(
        <Provider store={store}>
            <AppWithNavigation />
        </Provider>
    )
}
相关问题