A
A
AntonHPL2021-05-31 13:50:54
React
AntonHPL, 2021-05-31 13:50:54

How to fix data loading in react-paginate?

While the data is being loaded, the word Loading... is displayed, indicating that it is being loaded.
But when switching from one page to another , the first page (as the active one) is always returned, even though the content changes.
In this regard:
1) How to make the correct page displayed? Everything worked before the Loading setup.
2) How to make sure that the word Loading is not alone on the screen during loading, but is in place of the data being loaded?

https://codesandbox.io/s/eager-oskar-471xm?file=/s...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2021-05-31
@0xD34F

While the data is loading, you destroy the pagination component, respectively, every time the page changes, it is recreated - therefore, its internal value of the current page is constantly defaulted.
Explicitly tell the pagination component which page to consider as the current page ( forcePage={currentPage}).
Remove +1 from the page selection handler, add one when requesting (it's easier to correct the value of the current page in one place than in two - this would also have to do -1 when specifying the page to the pagination component).

D
Dmitry Sviridov, 2021-05-31
@dimuska139

Something like this? https://codesandbox.io/s/young-cloud-l2l0x?file=/s...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question