React Native-渲染未返回任何内容 [英] React Native - Nothing was returned from render

查看:55
本文介绍了React Native-渲染未返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

}

我使用create react native软件包来构建此项目,然后尝试遵循一些指南来实现带有redux的react导航.

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

推荐答案

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

Your default export is not returning anything :

export default () => {

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

}

要使用箭头功能返回JSX,您需要使用()=>(< JSX/>)或带有花括号的等效项:()=>{return(< JSX/>)} :

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

或:

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

这篇关于React Native-渲染未返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆