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

213
Visualizações
How to render three dots in custom pagination in React

I have looked everywhere, watched videos and still couldn't get the logic behind adding ellipsis in pagination.

I have created this component Pagination (please note this is just a sample component to demonstrate my question)

export const Pagination (props) {
const {maxPages, pageNumber} = props

const totalPageNumbers = []

for(let i = 1; i<= maxPages; i++){
totalPageNumbers.push(i)
} 

return (
<div>
<button disabled={pageNumber === 1}>prev</button>

{
totalPageNumbers.map(item, i) => (
<button onClick={() => someFunction()}> {item} </button>)
}
<button disabled={pageNumber === maxPages}>prev</button>
</div>

)}
  • totalPageNumbers is an array of the total pages
  • maxPages is a string of the total number
  • pageNumber is the current page

I would like to show something like this if total pages are 5 or more 1, 2, 3, 4, ..., 5

if less than 5, it should be 1, 2, 3, 4

Right now everything works fine, but all pages are listed due to the map method above, so if I have 100, it will list 100. I would like to limit that number so it's cleaner. ellipsis no need to be clickable as long as they look like the example above, I will be super happy. Thanks a lot in advance!

Please help me with this logic, I have been stuck at this for the last 5 hours :(

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