mercredi 7 octobre 2020

conditional doesn't work as expected with array.includes in ReactJS [closed]

I'm trying to render conditionally in React and ran into the following problem:

this is working as expected, loging yes to the console if true and no if false:

  return (
     <div className="App">
       array_1.map((name) => (
        <ul>
          <li>
            {array_2.includes(name) ? console.log("yes") : console.log("no")}
          </li>
        </ul>
    ))
   }
  };

but for some reason the next one only renders "no":

   return (
       <div className="App">
         {array_1.map((name) => (
            <ul>
              <li>
                {array_2.includes(name) ? "yes" : "no"}
              </li>
            </ul>
        ))
       }
      };             

I can't figure out why this is happening. Can someone point me in the right direction? Thanks!

Aucun commentaire:

Enregistrer un commentaire