我正在使用一個簡單的演示來學習反應原生,我發現了一個奇怪的事情。反應原生不能在組件狀態使用布爾值
這是我的代碼:
export default class App extends Component {
constructor(props) {
super(props)
this.state = {success: false}
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit App.js.
{this.state.success} //this line can not be shown
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
</View>
);
}
}
我用設置的狀態在constructor()
但render()
不能訪問它,當我success
值設置爲一個字符串或整型,它就會顯示出來。
我的代碼有什麼問題嗎?爲什麼我不能使用布爾值?
默認情況下,布爾值不會顯示在React中。爲什麼你需要顯示一個布爾值? – mersocarlin
你期望看到什麼?字符串'false'? –
未定義或空值不會顯示任何,順便說一句。您可以使用此屬性進行條件呈現。 – JulienD