0

I want to render my component if id equal to 15 or 12. Here is below how I'm doing , but it doesnt work. It renders if leave only one id, but I need check for two statements

   {query_estate_id === 15  || 12   && <span
    onClick={() => this.toggleFlatsView(2)}
    className={cn({ active: flatsView === 2 })}
    >
      3d 
   </span>}
Yerlan Yeszhanov
  • 2,149
  • 12
  • 37
  • 67
  • 1
    `query_estate_id === 15 || query_estate_id === 12` – VLAZ Jun 20 '19 at 06:22
  • There has to be a good dupetarget for this... – T.J. Crowder Jun 20 '19 at 06:23
  • 1
    @T.J.Crowder trying to find it but it's super annoying to search for it... – VLAZ Jun 20 '19 at 06:24
  • @T.J.Crowder there it is! Well done! I keep forgetting the exact magical phrase to conjure it forth. I was trying "or many" and "one of many" and few variations. It's *list*. I just have to get a bunch of links in a document because there are few good dupes that are a pain to search for if you don't remember the exact title. – VLAZ Jun 20 '19 at 06:26
  • 1
    { [15,12].includes(query_estate_id) && – JenuJ Jun 20 '19 at 06:26

2 Answers2

0

You can't compare against two values like that in JavaScript. Instead, repeat the variable name:

{(query_estate_id === 15 || query_estate_id === 12) && ...
VLAZ
  • 26,331
  • 9
  • 49
  • 67
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

Try:

    {query_estate_id === 15 || query_estate_id === 12 ? (
      <span
        onClick={() => this.toggleFlatsView(2)}
        className={cn({ active: flatsView === 2 })}
      >
        3d
      </span>
    ) : null}
Raman Kishore
  • 542
  • 2
  • 12