簡體   English   中英

反應原生應用程序中的錯誤:不變違規:文本字符串必須在一個<Text>成分

[英]Error in react-native application: Invariant Violation: Text strings must be rendered within a <Text> component

這是我在 react-native 應用程序中編寫的代碼,我添加了有關在 android 虛擬設備上運行應用程序時遇到的錯誤的圖像。

import React from 'react';
import { Text, View } from 'react-native';

const Header = () => {
    const { textStyle, viewStyle } = styles;

    return (
        <View style={viewStyle}>
        <Text style={textStyle} >Albums!</Text>;
        </View>
    );
};

const styles = {
    viewStyle: {
        backgroundColor: '#F8F8F8'
    },
    textStyle: {
        fontSize:20
    }
};
export default Header;

錯誤如下:

Invariant Violation:文本字符串必須在 <Text> 組件中呈現。

只需刪除文本結束標記之后的分號。

return (
    <View style={viewStyle}>
    <Text style={textStyle} >Albums!</Text> "remove this semicolon ->;"
    </View>
);

如果你想要! 你可以寫這樣的代碼

return (
<View style={viewStyle}>
<Text style={textStyle} >{"Albums!"}</Text>
</View>

);

暫無
暫無

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

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