【问题标题】:Undefined is not a function (near '...(0,_reactNavigation.StackNavigator)...')未定义不是函数(在'...(0,_reactNavigation.StackNavigator)...'附近)
【发布时间】:2019-10-20 05:15:08
【问题描述】:

我正在做一个 React Native 的研究项目(天气应用程序)。我正在使用反应导航 v4。它给出了上述错误。请任何人帮助解决这个问题。

//Index.js

import React from "react";
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import { createStore, applyMiddleware } from 'redux';
import reducer from "./reducers";
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';

import { StackNavigator } from 'react-navigation';
import WeatherDetails from './screens/WeatherDetails';
import CityLists from './screens/CityLists';

const Navigation = StackNavigator({
  WeatherDetails: { screen: WeatherDetails },
  CityLists: { screen: CityLists }
});

const store = createStore(reducer, applyMiddleware(thunk));

const wrapper = () => {
  return (
    <Provider store={store}>
      <Navigation />
    </Provider>
  );
}

AppRegistry.registerComponent(appName, () => wrapper);

【问题讨论】:

    标签: react-native react-navigation stack-navigator


    【解决方案1】:

    react-navigationv(4.0) documentation 中所述,您必须单独安装StackNavigator。所以先安装StackNavigator

    npm install react-navigation-stack --save

    然后从react-navigation-stack导入createStackNavigator

    import { createStackNavigator } from 'react-navigation-stack';
    

    现在,创建导航:

    const Navigation = createStackNavigator ({
      WeatherDetails: { screen: WeatherDetails },
      CityLists: { screen: CityLists }
    });
    

    【讨论】:

    • 我做到了,并用文档中提到的 AppContainer 包装了导航。但是这次我收到了 AppContainer 不是函数的新错误
    • 我解决了这是我的错误。 createAppContainer 来自 react-navigation。我从 react-navigation-stack 导入了它。感谢您的帮助。
    猜你喜欢
    • 2019-05-27
    • 1970-01-01
    • 2019-04-22
    • 2019-05-10
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多