首页 > 解决方案 > 我如何运行反应原生项目

问题描述

我写了这段代码,但它不起作用并且有错误

import React, {Component} from 'react';
import {Platform, StyleSheet, Text} from 'react-native';
type Props = {};
export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Text style={styles.instructions}>To get started, edit App.js</Text>
        <Text style={styles.instructions}>{instructions}</Text>
      </View>
    );
  }
}

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

它与其他代码一样无法正常工作,并且我的应用程序崩溃请帮我解决它

标签: reactjsreact-native

解决方案


在您的代码中,您忘记在第二行代码中的组件中导入 View,您应该这样编写:

import {Platform, StyleSheet, Text, View} from 'react-native';

推荐阅读