应用程序主线程尚未在 React Native 中注册 [英] Application main thread has not been registered in react native

查看:49
本文介绍了应用程序主线程尚未在 React Native 中注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 React Native 编程的新手,我正在尝试在其中编写第一个程序.我面临以下问题:-

Hi I am new in react native programming, I am trying to make first program in it. I am facing below issue :-

import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';

class HelloWorldApp extends Component {
  render() {
    return (
      <Text>Hello world!</Text>
    );
  }
}

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

我正在使用这个工具 https://rnplay.org

推荐答案

使用rnplay时,需要调用

When you are using rnplay, You need to call

registerComponent(HelloWorldApp);

代替

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

Hello world 示例

Sample Hello world example

import React from 'react';
import {
  registerComponent,
} from 'react-native-playground';
import {
  StyleSheet,
  Text,
  View,
} from 'react-native';

class HelloWorldApp extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.instructions}>
         Hello world
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
  },
  instructions: {
    fontSize: 16,
    textAlign: 'center',
    margin: 15,
  },
});

registerComponent(HelloWorldApp);

这篇关于应用程序主线程尚未在 React Native 中注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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