I'm using a simple demo to learn react native, I found a strange thing.
This is my code:
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>
);
}
}
I use set a state in the constructor() but can not access it in render(), and when I set the success value to a string or int, it will display.
Is anything wrong in my code ? why can not I use boolean ?
false?undefinedornullwon't display either, btw. You can use this property for conditional rendering.falseas @MikhailShabrikov said.