I'm trying to add different Id to a component based on a certain value.
My approach is like below
id={activePage === ('dashboard' || 'evc_detail')? 'bg_gradient':'bg_normal'}
In this scenario if the activePage
is equal to dashboard
the correct id is added but it does not register if activePage
is equal to evc_detail
. Is the way i'm using this condition wrong and how can i solve this?
If you want to multiple comparisons you'll need to state them manually:
Another option is create an array of items (or a Set), and use
Array.includes()
(orSet.has
) to check if an item is in the group:Your original expression
activePage === ('dashboard' || 'evc_detail')? 'bg_gradient':'bg_normal'
doesn't work if theactivePage
is not 'dashbarod' because of the way it's evaluated:'dashboard' || 'evc_detail'
is evaluated, since 'dashboard' is a truthy expression, the result is alwaysdashboard
.activePage
. IfactivePage
is 'dashboard' the result istrue
, if not it'sfalse
.