Ad

If Else For More Than One Date Result

- 1 answer

How do you use an if else to see if there is more than one dates result?

<If condition={adv_event.dates > 0 }>
  <Then>
    <p>More than one</p>
  </Then>
  <Else>
    {adv_event.dates.length > 0 ? (
      <div className="col-md-4">
        {adv_event.dates &&
          <DateField props={adv_event.dates} />
        }
      </div>
    ) : ''}
  </Else>
</If>
Ad

Answer

it's simple use ternary operator.

class TodoApp extends React.Component {

    state = {
        adv_event :{
      data: 10
      }
    }


  render() {
  const {adv_event:{data}} = this.state;
    return (
      <div>
        {data >0? <div><p>More than one</p></div> : <div><p>no data</p></div>}
      </div>
    )
  }
}

here is a quick demo

Ad
source: stackoverflow.com
Ad