Error: Text strings must be rendered within a <Text> component in React Native when string is not empty
Error: Text strings must be rendered within a <Text> component in React Native when string is not empty
所以我最近 运行 进入文本标签中的错误显示,虽然我找不到它显示的原因。我已经记录了该值不为空,并且在我按下按钮之前该值已经存在。这是我的 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条件句末尾的分号
所以我最近 运行 进入文本标签中的错误显示,虽然我找不到它显示的原因。我已经记录了该值不为空,并且在我按下按钮之前该值已经存在。这是我的 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条件句末尾的分号