Reputation: 171
I am trying to render text in a text component that is conditional.
if, this.state.input
is an empty string,
then it should display this.props.value
.
otherwise, it should display this.state.input
is there a way to do that?
<text>{
code??
}</text>
Upvotes: 1
Views: 1099
Reputation: 933
The cleanest way would be
<Text>{this.props.input || this.props.value}</Text>
Which means if this.props.input
is not a falsy value(including an empty string), it will render that, otherwise, it will render this.props.value
.
Upvotes: 0
Reputation: 26258
Try this:
{
( this.state.input === '' ) // ternary operator for checking condition
?
this.props.value // if condition satisfy
:
this.state.input // if condition doesn't satisfy
}
Upvotes: 2