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

130
Vistas
How to map React component under correct category

I am able to map 3 objects as a normal list however how can I map it under the correct heading?

One way is to push each object to it's own array e.g. const employed = [] but it looks messy. Any suggestions for a better approach?

export const App = () => {
  const [list, setList] = useState([
    { name: "foo", status: "student" },
    { name: "bar", status: "employed" },
    { name: "foo", status: "unemployed" },
  ])
  const items = list.map(({name, status}, index) => {
        <Profile ... />
  })
  return (
    <div>
      <div>
        <h1>Students</h1>

      </div>
      <div>
        <h1>Employed</h1>
      </div>
      <div>
        <h1>Unemployed</h1>
      </div>
    </div>
  )
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Making three seperate lists using filter() would be one way to do it. Then you can show them as you need:

export const App = () => {
  const [list, setList] = useState([
    { name: "foo", status: "student" },
    { name: "bar", status: "employed" },
    { name: "foo", status: "unemployed" },
  ])

const students = list.filter(x => x.status === 'student' ).map(x => <Profile... />);
const employed = list.filter(x => x.status === 'employed' ).map(x => <Profile... />);
const unemployed = list.filter(x => x.status === 'unemployed' ).map(x => <Profile... />);

  return (
    <div>
      <div>
        <h1>Students</h1>
         {students}
      </div>
      <div>
        <h1>Employed</h1>
          {employed}
      </div>
      <div>
        <h1>Unemployed</h1>
          {unemployed}
      </div>
    </div>
  )
}

about 4 years ago · Juan Pablo Isaza Denunciar

0

Keep another mapping to your statuses to header values and filter the list according to the statuses.

This would also work.

import { useState } from "react";

const STATUSES = {
  student: "Studnets",
  employed: "Employed",
  unemployed: "Unemployed",
  retired: "Retired"
};

const App = () => {
  const [list, setList] = useState([
    { name: "foo", status: "student" },
    { name: "bar", status: "employed" },
    { name: "foo", status: "unemployed" },
    { name: "baz", status: "student" }
  ]);

  return (
    <div>
      {Object.entries(STATUSES).map(([statusKey, displayValue]) => {
        const data = list
          .filter(({ status }) => status === statusKey)
          .map(({ name, status }, index) => <div>{name}</div>);
        if (data.length > 0) {
          return (
            <div>
              <h1>{displayValue}</h1>
              {data}
            </div>
          );
        }
      })}
    </div>
  );
};

export default App;

Edit unruffled-bhaskara-slrg24

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