【问题标题】:ESLint: App.js (22:21) Parsing error: Unexpected token, expected ";"ESLint:App.js (22:21) 解析错误:意外的令牌,预期的“;”
【发布时间】:2020-09-13 10:26:07
【问题描述】:

错误:

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

我尝试了数千种方法,但没有任何效果。

【问题讨论】:

    标签: android react-native expo


    【解决方案1】:

    您声明了一个函数“App”并将其视为一个类。一个简单的解决方案是使用类来代替

        export default class App extends Component{
    // 
    }
    

    为了继承你正在寻找的东西。

    安全标志:不要在互联网的任何地方发布您的 api 密钥或敏感信息

    【讨论】:

    • 嘿,谢谢你的回答。它的工作,但现在有更多的错误像51 | 52 | return ( &gt; 53 | &lt;Container style={styles.container}&gt; | ^ 54 | &lt;Form&gt; 55 | &lt;Image 56 | style={{height:170 , width:170, alignItems: 'center',}}这个
    • 你能发送实际的错误信息吗?我只看到一段代码。
    猜你喜欢
    • 2021-10-17
    • 2021-03-28
    • 1970-01-01
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    • 2020-02-17
    • 2020-11-15
    • 1970-01-01
    相关资源
    最近更新 更多