React本机错误AppRegistry未定义?

时间:2017-07-12 15:16:01

标签: ios node.js reactjs react-native

我一直在尝试通过npm导入外部模块进入我的反应应用程序,然后跟随https://www.npmjs.com/package/react-native-material-design我试图合并材料设计。我还从'react'

导入了Stylesheet等组件

我是新来回应原生,不明白为什么我在重新运行后得到以下错误:

enter image description here

这就是我所拥有的,我正在定义App注册表,因为我的应用名称是SkysReact:

import React, { Component } from 'react';
import { Button, Card } from 'react-native-material-design';
import {
  StyleSheet,
  Text,
  View,
  Animated,
  Easing,
  ScrollView,
  RefreshControl
} from 'react-native';

//import AwesomeComponent from "./awesome.js";

//BODY
export default class SkysReact extends Component {
  render() {
    return (<View>
    {this.test()}
    </View>);
  }

  test() {
  console.log("Hello World")
}

animate()
{
  console.log("animate");
}
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#000',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
    color: '#333333'
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

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

有什么问题?它在我添加导入之前运行,无法理解错误。

2 个答案:

答案 0 :(得分:1)

您忘记导入AppRegistry。将其添加到您的导入语句将清除您的问题

import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Animated,
  Easing,
  ScrollView,
  RefreshControl
} from 'react-native';

答案 1 :(得分:0)

您需要从react-native导入AppRegistry。

import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Animated,
  Easing,
  ScrollView,
  RefreshControl
} from 'react-native';