如何解决错误:当字符串不为空时,文本字符串必须在 React Native 的 <Text> 组件中呈现
所以我最近在 text 标签中遇到了错误显示,尽管我找不到它显示的原因。我已经记录了该值不为空并且在我按下按钮之前该值存在。这是我的 jsx 代码:
<TouchableOpacity style={styles.profilePhotoBack} onPress={() => addProfilePhoto()}>
{profilePhoto ? (
<Image style={styles.image} source={{uri: profilePhoto}} />
) : (
<View style={styles.profilePhoto}>
<AntDesign name="plus" size={50} color="white" />
</View>
)};
</TouchableOpacity>
这是我的函数代码和状态:
const [profilePhoto,setProfilePhoto] = useState();
const getPermission = async () => {
if (Platform.OS !== "web") {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
return status;
}
};
const pickImage = async () => {
try {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,allowsEditing: true,aspect: [1,1],quality: 0.5
});
if (!result.cancelled) {
setProfilePhoto(result.uri);
}
} catch (err) {
alert("Error picking image. Please try again later.");
}
};
const addProfilePhoto = async () => {
const status = await getPermission();
if (status !== "granted") {
alert("Please allow access to your camera roll to create your profile photo.");
return;
}
await pickImage();
};
任何帮助都将不胜感激,因为我已经在这里呆了很长一段时间了。谢谢!
解决方法
去掉Touchable Opacity结束标签前的profilePhoto结尾的分号
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。