如何解决“不变违规:AppRedux(...):渲染未返回任何内容。”

时间:2019-08-23 10:52:11

标签: react-native

enter image description here

//App.js

import {createDrawerNavigator,createAppContainer} from 'react-navigation'
import Homescreen from './src/pages/homeSceen/Home'
import Userscreen from './src/pages/User';
import Login from './src/pages/login/login'

const MyDrawerNavigator = createDrawerNavigator({
  login:Login,
  Home:Homescreen,
  Users:Userscreen
},{
  drawerType:'slide'
});

export default createAppContainer(MyDrawerNavigator);

import {AppRegistry} from 'react-native';
import App from './App';
import React from 'react'
import Provider from 'react-redux'
import {createStore,applyMiddleware} from 'redux'
import promiseMiddleware from 'redux-promise'
import reducers from './src/store/reducers'
const createStoreWithMiddleware= applyMiddleware(promiseMiddleware)(createStore)
const AppRedux=()=>{
    <Provider store= {createStoreWithMiddleware(reducers)}>
    <App/>
    </Provider>
    
}
AppRegistry.registerComponent('react01',()=>AppRedux);

我正在将redux添加到我的登录应用程序中,为此,我突然将提供程序用于一个正在运行的应用程序中。

我也尝试过

 import {AppRegistry} from 'react-native';
 import App from './App';
 import React from 'react'
 import Provider from 'react-redux'
 import {createStore,applyMiddleware} from 'redux'
 import promiseMiddleware from 'redux-promise'
 import reducers from './src/store/reducers'
 const createStoreWithMiddleware= applyMiddleware(promiseMiddleware)(createStore)
 const AppRedux=()=>{
     <Provider store= {createStoreWithMiddleware(reducers)}>
     <App/>
     </Provider>

 }
 AppRegistry.registerComponent('react01',()=>AppRedux);

预期成功构建,但导致错误。

2 个答案:

答案 0 :(得分:1)

您忘记将return放在AppRedux函数上

const AppRedux=()=>{
    return (
    <Provider store= {createStoreWithMiddleware(reducers)}>
    <App/>
    </Provider>
    )
}

答案 1 :(得分:0)

更改:

const AppRedux = () => {
   <Provider store= {createStoreWithMiddleware(reducers)}>
      <App/>
   </Provider>
}

收件人:

const AppRedux = () => ( 
   <Provider store= {createStoreWithMiddleware(reducers)}>
      <App/>
   </Provider>
)

注册必须类似于:

AppRegistry.registerComponent('react01', () => AppRedux);