My simple classname logic is not comparing right (React)

Asked

Viewed 30 times

-1

I’m making a comparison logic within Classname, follows:

<button className={'OVERDUE' || 'CONFIRMED' || 'RECEIVED' === 'PENDING' ? 'YES' : 'NO'} onClick={ () => this.showModalEdit(payment)} >My button</button>

The problem with the code is that it always comes back YES.

  • I’m a little confused by what you tried to do. What was the expected behavior?

  • You’re not comparing anything to variables. Assemble your logic into one if first and then try to put in className, if you wish

1 answer

0


It would validate each of the status and put the backlog as: yes or no?

let $status = null
let $render = null

//verifica o status e cria um JSX a partir do resultado
if (($status === 'OVERDUE') || ($status === 'CONFIRMED') || ($status === 'RECEIVED')) {
   $render = <button className="PENDING YES"> onClick={ () => 
          this.showModalEdit(payment)} > My button</button>
   } else {
       $render = <button className="PENDING NO"> onClick={ () => this.showModalEdit(payment)} > My button</button> }

//Reinderiza o objeto $ render a partir da condição
<div>
{$render}
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.