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

85
Views
Error trying to render a table dynamically

I'm aiming to build a pagination in my application. I wanted to test if I would render the table with the 10 rows, using slice and map. The problem is that I am not able to render my table. No errors appear in the console. I did it according to the code below:

Obs: The date return is an array of objects.

  import { Container } from "./styles"
import ReactPaginate from "react-paginate"
import { useState } from "react"
import data from "../../data/data.json"

export const BillingList = () => {
    const [stores, setStores] = useState(data.stores.slice(0, 50))
    const [pageNumber, setPageNumber] = useState(0)

    const storesPerPage = 10
    const pagesVisited = pageNumber * storesPerPage

    return (
        <Container>
            <table>
                <thead>
                    <tr>
                        <th>Loja</th>
                        <th>Faturamento</th>
                    </tr>
                </thead>

                <tbody>
                    {stores.slice(pagesVisited, pagesVisited + storesPerPage)
                        .map((store) => {
                            <tr>
                                <td>{store.name}</td>
                                <td>{store.revenue}</td>
                            </tr>
                        })}
                </tbody>
            </table>
        </Container>
    )
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The problem is in the .map() function. You don't need to do { } and instead to ( ).

Do like this:

        <tbody>
          {stores.slice(pagesVisited, pagesVisited + storesPerPage)
            .map((store) => (
              <tr>
                <td>{store.name}</td>
                <td>{store.revenue}</td>
              </tr>
            ))}
        </tbody>

Reason:

() => {return 'someValue';} 

is equal to

() => ('someValue')

You can approach either of them. Add return or change parenthesis.

about 4 years ago · Juan Pablo Isaza Report

0

In table body you are missing "return" while using map (whenever you use curly brace with map function the content does not return automatically you have to return manually); Please add return in map function

let tempArray=[1,2,3,4,5]

//Issue in above mentioned problem

let res=tempArray.map((element)=>{ element})
console.log("Map map does not return anything",res)

//SOLUTIONS

//Solution 1
res=tempArray.map((element)=>element)
console.log("Map funtion without {}",res)
//Solution 2
res=tempArray.map((element)=>{return element})
console.log("Map funtion with {} now we have to add return",res)

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