【发布时间】:2019-12-29 08:23:10
【问题描述】:
React 很新,所以问题可能很简单,但我收到以下错误:
意外的令牌,应为“;”错误 。
错误发生在 render() 函数所在的位置。我该如何解决这个问题?
import React, {Component} from 'react';
import { StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native';
type Props = {};
export default class App extends Component{Props} {
render() {
return (
<View style={styles.container}>
<Text>style={styles.welcome}>Login To</Text>
<Text>style={styles.design}>North Mall</Text>
<TextInput
style={styles.input}
placeholder="Username"
/>
<TextInput
style={styles.input}
placeholder="Password"
secureTextEntry
/>
<View style={styles.btnContainer}>
<TouchableOpacity
style={styles.userBtn}
onPress={() => alert("Login Works")}
>
<Text style={styles.btnTxt}>Login</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.userBtn}
onPress={() => alert("Signup Works")}
>
<Text style={styles.btnTxt}>Signup</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#0057ff'
},
welcome:{
fontSize: 30,
textAlign: 'center',
margin: 10,
color: "#fff",
fontFamily:"DancingScript-Bold"
}
}}
代码继续,但我很确定错误出现在代码的第一部分。
【问题讨论】:
-
请从我不关心的代码顶部删除类型,以便有数据类型或清除 const 或让
-
@VishalDhanotiya 我删除了下一行中的类型行和道具:export default class App extends Component { 但现在它给出了 Invariant Violation: objects are not valid as React child...
标签: react-native unexpected-token