S
S
Smuzzzzi2019-01-07 21:48:43
React
Smuzzzzi, 2019-01-07 21:48:43

Like if else react?

There is a default div It is necessary to assign the class positive if the value is greater than 0 If the value is less than 0 I do this, but if the value is less than 0 it still costs positive
<div className="vote">

<div className="vote positive">

<div className="vote negative">

<div className={"vote" + (article.total_comments.length > 0 ? '' : " positive")  + (article.total_comments.length < 0 ? '' : "negative")}>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-01-07
@Smuzzzzi

Reread carefully what you wrote there - if the value is greater than zero, then an empty string, otherwise 'positive'. You seem to need the opposite. The same is true for the second condition.
In general, it is possible and simpler, without conditions:

['negative', '', 'positive'][Math.sign(article.total_comments.length) + 1]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question