ESLint: App.js (22:21) Ошибка синтаксического анализа: ожидаемый неожиданный токен «;»

#android #react-native #expo

#Android #react-native #выставка

Вопрос:

Ошибка:

 ESLint: App.js (22:21) Parsing error: Unexpected token, expected ";"
  20 |     export default function App() {
  21 |   
> 22 |     constructor(props){
     |                     ^
  23 |     super(props)
  24 | 
  25 |     this.state = ({ (null)
  

Код:

 import React from 'react';
import { StyleSheet, Image, Text, View } from 'react-native';
import { Container, Content, Header, Form, Input, Item, Button, Label, } from 'native-base';

import * as firebase from 'firebase';

var firebaseConfig = {
apiKey: "AIzaSyB387ecmvoIcHvboydLrxL_vwBJqWHhXGw",
authDomain: "shootgeorgiaapp.firebaseapp.com",
databaseURL: "https://shootgeorgiaapp.firebaseio.com",
projectId: "shootgeorgiaapp",
storageBucket: "shootgeorgiaapp.appspot.com"
};

if (!firebase.apps.length){
firebase.initializeApp(firebaseConfig);
}

export default function App() {

constructor(props){
super(props)

 this.state = ({
   email:'',
  password:''
 })
}

signUpUser = (email,password) =>{
    try{

   if(this.state.password.length<6){
     alert("გთხოვთ მიუთთოთ 6-ზე მეტ ციფრიანი პაროლი")
    return;
   }

  firebase.auth().createUserWithEmailAndPassword(email,password)


 }
 catch(error){
   console.log(error.toString())
 }
}

logInUser = (email,password) =>{

}

return (
 <Container style={styles.container}>
  <Form>
      <Image 
      style={{height:170 , width:170, alignItems: 'center',}}
      source={require('./img/logo.png')}
      />

    <Item floatingLabel> 
      <Label>Email</Label>
      <Input
      autoCorrect={false}
      autoCapitalize="none"
      onChangeText={(email) => this.setState({email})}
      />
    </Item>

    <Item floatingLabel> 
      <Label>Password</Label>
      <Input
      secureTextEntry={true}
      autoCorrect={false}
      autoCapitalize="none"
      onChangeText={(password) => this.setState({password})}
      />
    </Item>

  <Button style={{marginTop:10} }
  full 
  rounded
  success
  onPress={() => this.logInUser(this.state.email,this.state.password)}
  >
    <Text style={{color:'white'}}>Log in</Text>
  </Button>

  <Button style={{marginTop:10} }
  full 
  rounded
  primary
  onPress={() => this.signUpUser(this.state.email,this.state.password)}
  >
    <Text style={{color:'white'}}>Sign in</Text>
  </Button>
  </Form>
</Container>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
justifyContent: 'center',
padding: 10,
},
});
  

Я перепробовал тысячи вещей, но ничего не работает.

Ответ №1:

вы объявляете функцию «Приложение» и рассматриваете ее как класс. Простое решение заключается в том, что вы используете классы вместо

     export default class App extends Component{
// 
}
  

чтобы наследовать то, что вы ищете.

Флаг безопасности: не размещайте свои ключи api нигде в Интернете или конфиденциальную информацию

Комментарии:

1. привет, спасибо за ответ. он работает, но теперь есть больше ошибок, подобных 51 | 52 | return ( > 53 | <Container style={styles.container}> | ^ 54 | <Form> 55 | <Image 56 | style={{height:170 , width:170, alignItems: 'center',}} этой

2. можете ли вы отправить фактическое сообщение об ошибке? Я вижу только фрагмент кода.