how can i run react native project

Viewed 40

i write this piece of code but it does not work and have error

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,
  },
});

and it does not work well as other codes and my app crash please help me to solve it

2 Answers

in your piece of code you forget to import View in component in the second line code you should write like this:

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

in this you didn't import View component so import the View component as below

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