React Native - Nothing was returned from render

2020-04-08 11:56发布

My application is stored in /src/index.js but i also have a /App.js and a /index.js.

I don't know the difference between these and i think thats the reason im getting this error.

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>

}

I used create react native package to build this project and then tried to follow some guides to implement react navigation with redux.

2条回答
Anthone
2楼-- · 2020-04-08 12:04

You forgot to return the components

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


export default () => {
    return(
        <Provider store={store}>
            <AppWithNavigation />
        </Provider>
    )
}
查看更多
等我变得足够好
3楼-- · 2020-04-08 12:14

Your default export is not returning anything :

export default () => {

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

}

To return JSX with an arrow function you need to use () => ( <JSX /> ) or the equivalent with curly braces : () => { return ( <JSX /> ) } :

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

or :

export default () => {
    return (    
       <Provider store={store}>
           <AppWithNavigation />
       </Provider>
   )
}
查看更多
登录 后发表回答