Skip to content
Advertisement

I want to paginate data. It is working fine but when I search for specific data it always shows in the first page

What I want is to paginate my data but the problem is when I’m searching for specific data if I’m on page 3 the result shows on page 1 always and I can’t see anything because I was on page no 3. I want to go to page 1 automatically when I’m searching for something. Also when I press the next button if there is no data at all it still increases the page number.

Here is my code:

JavaScript

Advertisement

Answer

Maybe with a useEffect on your input:

JavaScript

That way, whenever your input changes, your page number is set to 1.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement