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

141
Vistas
Function for each mapped item in React.js

I have a function, which makes axios request to backend and returns me data about the category by category_id. In two words, it returns me a length of elements in table with this parameters.

async function getLength(category_id) {
    const res = await axios
      .post("/api/passwords/categories", {
        category_id,
        user_id,
      })
      .catch((err) => console.error(err));

    return res;
  }

  async function length(category_id) {
    const res = await getLength(category_id).then((data) => {
      return data.data.length;
    });

    console.log("WIP length: ", res);
    return res;
  }

I need for every mapped item make a request to function length() to take it's data:

 {categories.map((x, index) => {
            return (
              <div key={index} className="col-xl-3 col-lg-3 col-md-3 col-6">
                <div className="dashboard__categories-item">
                  <span style={{ color: `${x.color}` }}>{x.icon}</span>
                  <h5>{x.title}</h5>
                  <h5>Length: {length(x.id)})</h5>
                </div>
              </div>
            );
          })}

But, I have an error: error message image

It makes my brain more than 3 hours. Please, help me :D

about 4 years ago · Juan Pablo Isaza
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