am starting with React Nturn on and always give me this error cant find variable:Component

Asked

Viewed 139 times

-2

inserir a descrição da imagem aqui

index.js
import {AppRegistry} from 'react-native'
import App from './app'
import {name as appName} from './app.json'

AppRegistry.registerComponent(appName,() => App)

app.js
import React,{Component} from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends component {
  render(){
    return(
      <text>test</text>
    )
  }
}

2 answers

1

The word "Component" should be capitalized. Also, "text" should be imported from the "React-Native" library. Component names in React should always start with uppercase. Change your code to look like this:

import {AppRegistry, Text} from 'react-native'
import App from './app'
import {name as appName} from './app.json'

AppRegistry.registerComponent(appName,() => App)

app.js
import React,{Component} from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends Component {
  render(){
    return(
      <Text>test</Text>
    )
  }
}

  • HELPED A LOT vlw , I will pay more attention to these details

-1

You need to import the Component to use it, and it must have the first letter capitalized:

import React, { Component } from 'react';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.