“Kondisional JSX:” Kode Jawaban

Properti JSX bersyarat

render() {
  return (
    <a className="navbar-brand" {... url ? {href: url} : {}}>Logo</a>
  )
}
Angry Aardvark

Kondisional JSX:

/*
&& works best in conditionals that will sometimes do an action, but other times do 
NOTHING at all.
*/

const tasty = (
  <ul>
    <li>Applesauce</li>
    { !baby && <li>Pizza</li> }
    { age > 15 && <li>Brussels Sprouts</li> }
    { age > 20 && <li>Oysters</li> }
    { age > 25 && <li>Grappa</li> }
  </ul>
);

/*
If the expression on the left of the && evaluates as true, then the JSX on the 
right of the && will be rendered. If the first expression is false, however, then 
the JSX to the right of the && will be ignored and not rendered.
*/
M Hassan khan

Jawaban yang mirip dengan “Kondisional JSX:”

Pertanyaan yang mirip dengan “Kondisional JSX:”

Lebih banyak jawaban terkait untuk “Kondisional JSX:” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya