Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - Nothing was returned from render

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.

like image 923
Kay Avatar asked Jan 30 '18 11:01

Kay


2 Answers

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>
   )
}
like image 170
Dyo Avatar answered Sep 20 '22 22:09

Dyo


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>
    )
}
like image 31
Ahsan Ali Avatar answered Sep 17 '22 22:09

Ahsan Ali