Reputation: 1196
I have a simple list and I want to show or hide certain text if string is longer than 0 but I always get the same output("C") and it doesn't change even after the update
<li>{props.sen}{props.sen.length > 0 ? "" : "C"}</li>
<li>{props.sax}{props.sax.length > 0 ? "" : "C"}</li>
<li>{props.sac}{props.sac.length > 0 ? "" : "C"}</li>
Initial state for sen
,sax
and sac
is ""
but even after update where state updates to "value", C
still remains.
Upvotes: 0
Views: 453
Reputation: 1196
Solution was removing ">" and adding "==" instead of it. This is the correct code
<li>{props.sen}{(props.sen.length == 0 ? "" : "C")}</li>
<li>{props.sax}{(props.sax.length == 0 ? "" : "C")}</li>
<li>{props.sac}{(props.sac.length == 0 ? "" : "C")}</li>
Upvotes: 0
Reputation: 1606
I think you forgot the brackets, try this:
<li>{props.sen}{(props.sen.length > 0 ? "" : "C")}</li>
<li>{props.sax}{(props.sax.length > 0 ? "" : "C")}</li>
<li>{props.sac}{(props.sac.length > 0 ? "" : "C")}</li>
Upvotes: 1