React Native AppRegistry 不是可调用模块 [英] React native AppRegistry is not a callable module

查看:34
本文介绍了React Native AppRegistry 不是可调用模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学习学习 React Native O Reilly"中的教程时遇到了一个小问题.

I'm having a small issue with following a tutorial in "Learning react native O Reilly".

我正在使用第一个应用程序(WeatherProject),当我执行 react-native init WeatherProject 命令时,奇怪的是 index.ios.js 和 index.android.js 没有自动创建?我假设这是正常的.所以我创建了它们,并按如下方式填充它们:

I'm on the first app (WeatherProject) and when I did the react-native init WeatherProject command, strangely index.ios.js and index.android.js weren't automatically created? I'm presuming this is normal. So I created them, and filled them as below:

var React = require('react-native');var { AppRegistry } = 反应;var WeatherProject = require('./WeatherProject');AppRegistry.registerComponent('WeatherProject', () => WeatherProject);

然后我有如下的 WeatherProject.js 文件:

I then have the WeatherProject.js file as follows:

import React, { Component } from "react";

import { StyleSheet, Text, View, TextInput } from "react-native";

class WeatherProject extends Component {
  constructor(props) {
    super(props);
    this.state = { zip: "" };
  }

  _handleTextChange = event => {
    this.setState({ zip: event.nativeEvent.text });
  };

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          You input {this.state.zip}.
        </Text>
        <TextInput
          style={styles.input}
          onSubmitEditing={this._handleTextChange}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#F5FCFF"
  },
  welcome: { fontSize: 20, textAlign: "center", margin: 10 },
  input: {
    fontSize: 20,
    borderWidth: 2,
    padding: 2,
    height: 40,
    width: 100,
    textAlign: "center"
  }
});

export default WeatherProject;

并制作 index.js 文件如下:

and made the index.js file as follows:

import WeatherProject from "./WeatherProject";

export default WeatherProject;

我正在阅读的书是过时的还是我在做一些愚蠢的事情?但是当我在 iphone 模拟器上运行应用程序时,我收到错误AppRegistry 不是可调用模块.(调用 runApplication)"

Is the book that I'm following outdated or am I doing something stupid? But when I run the app on the iphone simulator I get the error "AppRegistry is not a callable module.(calling runApplication)"

推荐答案

您导入了错误的 AppRegistry 并做出反应.

You are importing wrong AppRegistry and react.

尝试将它们导入到您的 index.ios.js 和 index.android.js 中,如下所示:

Try importing them in your index.ios.js and index.android.js like this:

import React from 'react';
import { AppRegistry } from 'react-native';
import WeatherProject from './WeatherProject';

这应该可行.

您应该查看官方文档,这里是AppRegistry.registerComponent 的示例https://facebook.github.io/react-native/docs/props.html#content

You should check the official documentation, here it's a example of AppRegistry.registerComponent https://facebook.github.io/react-native/docs/props.html#content

这篇关于React Native AppRegistry 不是可调用模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆