【问题标题】:React native error AppRegistry not defined?未定义反应本机错误AppRegistry?
【发布时间】:2017-12-17 02:47:03
【问题描述】:

我一直在尝试通过 npm 将外部模块导入到我的 react 应用程序中,在关注 https://www.npmjs.com/package/react-native-material-design 之后,我正在尝试合并 Material design。我还从'react'导入了样式表等组件

我是原生反应新手,不明白为什么重新运行后出现以下错误:

这就是我所拥有的,我将应用注册表定义为我的应用名称是 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);

怎么了?在我添加导入之前它正在运行并且无法理解出了什么问题。

【问题讨论】:

    标签: ios node.js reactjs react-native


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您需要从 react-native 导入 AppRegistry。

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

      【讨论】:

        猜你喜欢
        • 2017-09-28
        • 1970-01-01
        • 1970-01-01
        • 2018-11-20
        • 2019-05-17
        • 2022-08-13
        • 2019-07-30
        • 2017-09-01
        • 1970-01-01
        相关资源
        最近更新 更多