If you want to multiple comparisons you'll need to state them manually:
(activePage === 'dashboard' || activePage === 'evc_detail') ? 'bg_gradient' : 'bg_normal'
Another option is create an array of items (or a Set), and use Array.includes()
(or Set.has
) to check if an item is in the group:
const gradientPages = ['dashboard', 'activePage']
gradientPages.includes(activePage) ? 'bg_gradient' : 'bg_normal'
Your original expression activePage === ('dashboard' || 'evc_detail')? 'bg_gradient':'bg_normal'
doesn't work if the activePage
is not 'dashbarod' because of the way it's evaluated:
'dashboard' || 'evc_detail'
is evaluated, since 'dashboard' is a truthy expression, the result is always dashboard
.
- 'dashboard' is compared with
activePage
. If activePage
is 'dashboard' the result is true
, if not it's false
.