React Native Component未定义

时间:2019-05-26 16:20:20

标签: react-native react-native-android

我想用“ react-navigation”包创建一个新的StackNavigator 但是,当我初始化StackNavigator的屏幕时,出现错误-> undefined不是对象(正在评估'_TextUpload.TextUpload')

我的TextUpload组件:

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';

export class TextUpload extends Component {
 constructor(props){
 super(props);
 this.state = {
   ready: false
 }
 }

 render() {
 return (
   <View style={styles.container}>
     <Text style={styles.welcome}>
       Text Upload
     </Text>
   </View>
 );
}
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center'
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  }
});

我的StackNavigator组件:

import React from 'react';
import { createBottomTabNavigator, createAppContainer, createStackNavigator } from 'react-navigation';
import { Home, Profile, Feed, Upload, Notes, TextUpload, ImageScreen } from '../components';
import Icon from 'react-native-vector-icons/dist/FontAwesome';
import { createMaterialBottomTabNavigator } from "react-navigation-material-bottom-tabs";
import {HOME_TAB_COLOR, FEED_TAB_COLOR, UPLOAD_TAB_COLOR, NOTE_TAB_COLOR, PROFILE_TAB_COLOR} from "../config";

const AppNavigator = createStackNavigator({
  Home: {
    screen: TextUpload
  }
});

1 个答案:

答案 0 :(得分:1)

您需要在StackNavigator页面上导入页面。这就是我的使用方式;

import React, { Component } from "react";
import { createStackNavigator, createAppContainer } from 'react-navigation';

import Device from "../pages/device";
import DeviceScreen from "../pages/devices";

const Project= createStackNavigator({
    Measures: {
        screen: Device
    },
    Devices: {
        screen: DeviceScreen
    }
});
export default createAppContainer(Project);

在导入带有大括号的页面时会引发错误,因此请不要使用大括号。