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

86
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
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