How do I render an element based on a condition in React Native?
This is how I tried:
render() {
return (
<Text>amount is: {this.state.amount}</Text> // it correctly prints amount value
</Button>
{this.state.amount} >= 85 ? <button>FIRST</button> : <button>SECOND</button>
<Text>some text</Text>
);
}
But this error message appears:
Expected a component class, got [object Object]
You have misplaced your }:
render() {
return (
<Text>amount is: {this.state.amount}</Text>
{this.state.amount >= 85 ? <button>FIRST</button> : <button>SECOND</button>}
<Text>some text</Text>
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With