Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!