它在运行时给出此错误:undefined不是函数(评估'_reactNativr.default.createElement')

时间:2019-02-06 07:31:47

标签: react-native

这部分代码未运行,它始终返回错误,提示渲染function()中是否存在未定义的函数。


标题

'use strict';
import React, {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    TouchableHighlight,
    AlertIOS,
    Dimensions,
    BackHandler,
    PropTypes,
    Component,
} from 'react-native';

import NavigationExperimental from 'react-native-deprecated-custom- 
components';

var _navigator;
//var Navipanel=require('./App/Navigation/Navipanel.js');
var Dashboard= require('./App/Dashboard/dashboard.js');
//var Sample= require('./App/Navigation/sample.js');
var Matches = require('./App/Components/Matches.js');
var Users = require('./App/Components/Users.js');
var SCREEN_WIDTH =require('Dimensions').get('window').width;
var BaseConfig=NavigationExperimental.Navigator.SceneConfigs.FloatFromRight;

var CustomLeftToRightGesture = Object.assign({}, BaseConfig.gestures.pop, 
    {
        snapVelocity: 8,
        edgeHitWidth: SCREEN_WIDTH,
    });

BackHandler.addEventListener('hardwareBackPress', () => {
     if (_navigator.getCurrentRoutes().length === 1) {
         return false;
     }

     _navigator.pop();
     return true;
});

var CustomSceneConfig = Object.assign({}, BaseConfig, {
    // A very tighly wound spring will make this transition fast
    springTension: 100,
    springFriction: 1,
    // Use our custom gesture defined above
    gestures: {
        pop: CustomLeftToRightGesture,
    }
});

//var createReactElement = require('create-react-element');
var createReactClass = require('create-react-class');
var test = createReactClass({
    _renderScene(route,navigator) {
        _navigator = navigator;

        if (route.id === 1) {
            return <Dashboard navigator={navigator}/>;
        }
        else if(route.id === 2) {
            return <Sample navigator={navigator} /> ;
        }
        else if(route.id === 3) {
            return <Navipanel navigator={navigator} /> ;
        }
        else if(route.id === 4){
            return <Matches navigator={navigator} /> ;
        }
        else if(route.id === 5) {
            return <Users navigator={navigator} />
        }
    },

    _configureScene(route) {
        return CustomSceneConfig;
    },

    render:function() {
        return (
            <NavigationExperimental.Navigator  [//error in this line]
            initialRoute = {{id:1}}
            renderScene = {this._renderScene}
            configureScene = {this._configureScene} />
        );
    }
});

未定义错误_reactNative.default.createElement

enter image description here

1 个答案:

答案 0 :(得分:0)

您从“ react-native”导入了React;

import React, {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableHighlight,
  AlertIOS,
  Dimensions,
  BackHandler,
  PropTypes,
  Component,
} from 'react-native';

相反,您需要从“反应”中导入React;

import React from 'react';

当我们在渲染函数中使用JSX时,JSX在后台运行React.createElement(...)。而且在您的代码中,未定义React。因此,它给出了该错误。