问题描述
我的应用程序存储在/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 package 来构建这个项目,然后尝试按照一些指南使用 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 - 渲染没有返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!