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

84
Vistas
Combining multiple maps in React

Hey I have the current standard component which maps over a list.

  return (
    <div className={classNames("vertical-list-rows", className)}>
      {list.listItemCollection.map((item, index) => (
        <StandardComponnet
          key={`${item.key}-${index}`}
          list={list}
          item={item}
        />
      ))}
    </div>
  );

I'm wondering though is it possible to perform another map - if a condition is true - to "add" an additional map to this logic:

const getFilteredList = (list: ListModel, references: Array<number>) => {
  const filteredList = list.clone();

  filteredList.listItemCollection = new ListItemCollection();
  filteredList.listItemCollection.collection = list.listItemCollection.filter(
    (listitem) => references.includes(listitem.id)
  );

  return filteredList;
};


  return (
    <div className={classNames("vertical-list-rows", className)}>
      {list.grouping.groups.map((group) => {
        const filteredList = getFilteredList(list, group.reference);
        <StandardComponnet
          key={`${item.key}-${index}`}
          list={list}
          item={item}
        />;
      })}
    </div>
  );

So the first snippet is the component's standard behaviour, but if a condition is true, I'd like to map over the second snippet as well - is this possible?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Use the ternary operator, and either return an array map or null.

function List() {
  const arr = ['a', 'b', 'c']
  return (
    <div>
      {
        arr.map(val => {
          return (
            <div>
              {val}
              {
                val==='a' ? [1,2,3].map(num => {
                  return <div>{num}</div>
                })
                : null
              }
            </div>
          )
        }
      }
    </div>
  )
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

For me, I often use this style of code:

<View>
{[
  ...list1,
  ...(<condition> ? list2 : []),
  ...(<condition> ? list3 : []),
].map(item => (
  /* render what you need */
))}
</View>
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