G
G
GF2020-10-16 22:14:41
JavaScript
GF, 2020-10-16 22:14:41

How to simplify the condition for the paginator?

https://repl.it/@fomenkogregory/Paginator-5#src/App.js

I created such a paginator, how to simplify the condition without changing the behavior? Help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-10-17
@fomenkogregory

Let's put into separate variables the conditions that determine whether it is necessary to show groups of buttons that ...

// ...прилегают к первой кнопке
const showAfterFirst = currentPage < 5;

// ...прилегают к последней кнопке
const showBeforeLast = currentPage > totalPages - 4;

Accordingly, the conditions for displaying ellipsis after/before the first/last buttons will be the reverse values: !showAfterFirstand !showBeforeLast. And to display the central group of buttons, both base conditions must be false: !(showAfterFirst || showBeforeLast).
https://jsfiddle.net/0sjgrcxu/1/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question