我的代码是
import React from 'react';
import { Text, StyleSheet, View } from 'react-native';
const ComponentsScreen = () => {
return {
<View>
<Text style={styles.testStyle}>This is the components screen</Text>
</View>
};
};
const styles = StyleSheet.create({
testStyle: {
fontSize: 30
}
});
export default ComponentsScreen;
Run Code Online (Sandbox Code Playgroud)
我收到一个错误,显示在我的开始视图标记处预期有属性分配,在我的结束视图标记和关闭 ComponentsScreen 的括号处预期出现声明或语句错误,在结束我的 return 语句的括号处预期有表达式。有什么解决办法吗?
在组件屏幕 jsx 中,使用括号中的 return 语句而不是大括号 {} 。
所以只需替换这个:
const ComponentsScreen = () => {
return (
<View>
<Text style={styles.testStyle}>This is the components screen</Text>
</View>
);
};
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你。如有疑问请放心
| 归档时间: |
|
| 查看次数: |
20692 次 |
| 最近记录: |