簡體   English   中英

錯誤:文本字符串必須在<text>字符串不為空時 React Native 中的組件</text>

[英]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>

這是我的 function 代碼以及 state:

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

任何幫助將不勝感激,因為我已經在這里停留了很長一段時間。 謝謝!

移除 ProfilePhoto 末尾的分號,條件是 Touchable Opacity 的結束標記之前

通常它可能是由以下2個錯誤引起的:

  1. 視圖中的剩余分號
  2. 導入錯誤的路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM