Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda