最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Native - Nothing was returned from render - Stack Overflow

programmeradmin3浏览0评论

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.

/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.

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.

/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.

Share Improve this question edited Jul 30, 2019 at 2:28 Emile Bergeron 17.4k5 gold badges85 silver badges131 bronze badges asked Jan 30, 2018 at 11:25 KayKay 19.7k71 gold badges183 silver badges300 bronze badges 1
  • you haven't exported App in index.js that you're importing in App.js – Deepansh Sachdeva Commented Jan 30, 2018 at 11:29
Add a ment  | 

3 Answers 3

Reset to default 10

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>
   )
}

You forgot to return the ponents

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


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

I didn't mention this

import React from 'react';

and all other react-native ponents in my other files of screens.

Because I was calling my screen ponent from another file, from App.js file, so I also had to import react and react-native ponents in that file too.

发布评论

评论列表(0)

  1. 暂无评论