javascript - 来自 Facebook 的 React Native Navigator 示例代码失败 : type is invalid: expected a string (for built-in components) or a class/function

标签 javascript ios react-native

相关/类似的问题是犯了一些简单的错误(属性的大小写不正确)等。我使用的代码是直接从 React Native 站点提取的,所以看起来它应该可以工作。

我正在尝试将 Navigator 组件调整到一个非常简单的现有应用程序中。我从 React Native 页面上的基本导航器开始:https://facebook.github.io/react-native/docs/using-navigators

./src/scene/myScene.jsx.js(直接从教程中提取):

import React, { Component, PropTypes } from 'react';
import { View, Text, TouchableHighlight } from 'react-native';

export default class MyScene extends Component {
  render() {
    return (
      <View>
        <Text>Current Scene: {this.props.title}</Text>

        <TouchableHighlight onPress={this.props.onForward}>
          <Text>Tap me to load the next scene</Text>
        </TouchableHighlight>

        <TouchableHighlight onPress={this.props.onBack}>
          <Text>Tap me to go back</Text>
        </TouchableHighlight>
      </View>
    )
  }
}

MyScene.propTypes = {
  title: PropTypes.string.isRequired,
  onForward: PropTypes.func.isRequired,
  onBack: PropTypes.func.isRequired,
};

index.ios.js(与示例代码几乎相同):

import React, {Component} from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableHighlight,
  Navigator
} from 'react-native'; 
import {MyScene} from './src/scene/myScene.jsx.js'

export default class kisharNine extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <Navigator
        initialRoute={{ title: 'My Initial Scene', index: 0 }}
        renderScene={(route, navigator) =>
          <MyScene
            title={route.title}

            // Function to call when a new scene should be displayed
            onForward={() => {
              const nextIndex = route.index + 1;
              navigator.push({
                title: 'Scene ' + nextIndex,
                index: nextIndex,
              });
            }}

            // Function to call to go back to the previous scene
            onBack={() => {
              if (route.index > 0) {
                navigator.pop();
              }
            }}
          />
        }
      />
    )
  }

}

AppRegistry.registerComponent('kisharNine', () => kisharNine);

错误堆栈:

type is invalid: expected a string (for built-in components) or a class/function (for composite 
components) but got: undefined. Check the render method of `Navigator`.

instantiateReactComponent
    instantiateReactComponent.js:77
instantiateChild
    ReactChildReconciler.js:56
<unknown>
    ReactChildReconciler.js:88
traverseAllChildrenImpl
    traverseAllChildren.js:83

我能看到的唯一区别是构造函数。删除它没有任何区别。这可能是示例代码中的错误吗?

最佳答案

我认为问题是 import {MyScene} from './src/scene/myScene.jsx.js',因为你正在做 export default 它应该是:import MyScene from './src/scene/myScene. jsx.js'

关于javascript - 来自 Facebook 的 React Native Navigator 示例代码失败 : type is invalid: expected a string (for built-in components) or a class/function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40938617/

相关文章:

javascript - 错误: [$injector:unpr] Unknown provider: $scope in angular Js when routing

ios - 将 UITableview 添加为 UIView 的 subview 时出现问题

javascript - '安卓 :name' in <activity> tag must be a valid Java class name in React Native

reactjs - 在 React Native 中渲染逗号分隔的值字符串

ios - 什么决定了window.frame?

javascript - React Native with react-navigation and Redux - 如何实现全局可用的 'Sign Out' 按钮

javascript - 如何在我的网站上禁用或隐藏不需要的 Disqus 广告?

javascript - 如何禁用 ASP.NET Web 中的默认 CSS?

javascript - React Js 使用 onChange 将数组内的值更新为子组件

iphone - 如何根据最后的“/”从字符串中选择子字符串?