Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

228
Vistas
ReactJS Conditional Rendering - else if doesn't work

I'm in the stage of learning JS and React and I'm not sure why else if doesn't work in the code below. Anyone can help me?

  function Item({ name, isPacked }) {
  if (isPacked) {
    return (
      <li className="item">
        {name} {isPacked && " ✔"}
      </li>
    );
  } else if (!isPacked) {
    return (
      <li className="item">
        {name} {isPacked && " ❌"}
      </li>
    );
  }
}

export default function PackingList() {
  return (
    <section>
      <h1>Sally Ride's Packing List</h1>
      <ul>
        <Item isPacked={true} name="Space suit" />
        <Item isPacked={true} name="Helmet with a golden leaf" />
        <Item isPacked={false} name="Photo of Tam" />
      </ul>
    </section>
  );
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try like this:

function Item({ name, isPacked }) {
    return (
        <li className="item">
            {`${name} ${isPacked ? "✔" : '❌'} `}
        </li>
    );
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

you actually tested if the isPacked true or false so try this code:

function Item({ name, isPacked }) {
    return (
      <li className="item">
        {name}  {isPacked ? "✔" : "❌" }
      </li>
    );
}

{isPacked ? "✔" : "❌" } so this line of code is equal to:

  if(isPacked == true){
      return "✔";
    }else{
      return "❌";
    }

You can get some helpful examples Here https://reactjs.org/docs/conditional-rendering.html.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda