Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clickCallback gets called without a click #91

Closed
hackingbeauty opened this issue Jul 1, 2016 · 13 comments
Closed

clickCallback gets called without a click #91

hackingbeauty opened this issue Jul 1, 2016 · 13 comments

Comments

@hackingbeauty
Copy link

Hello,

I noticed that when react-paginate first gets displayed on a page, it automatically calls the clickCallback handler.

I don't want it to do this. I just want the clickCallback handler called when a page number is clicked.

Am I doing something wrong?

@hackingbeauty hackingbeauty changed the title clickCallback gets called with out a click clickCallback gets called without a click Jul 1, 2016
@AdeleD
Copy link
Owner

AdeleD commented Jul 14, 2016

Hello @hackingbeauty,

Indeed, when react-paginate first gets displayed on a page, it automatically calls the clickCallback handler. That's because the clickCallback function is supposed to be the place where you load the content you want to display on a particular page.

As you can initialize the component to display the page of your choice (page 6 for example), it will call the clickCallback at first in order to load the content of page 6.

I hope this helps.

@jzlxiaohei
Copy link

the first data has been fetched, then the callback will fetch duplicated data again.

i don't think automatically calls the clickCallback is good.

@donperi
Copy link

donperi commented Aug 12, 2016

Having issues because of this too.
Data is loaded from other method.
onClick handles a pushState to a new url with the new page number.

Being called on mount causes me a loop.

@donperi
Copy link

donperi commented Aug 12, 2016

A solution could be to add another props like onLoad/onMount if is needed to call the handler when component is loaded.

@coljung
Copy link

coljung commented Sep 28, 2016

Might this be causing an issue where my initial page is linked to [2], where as [1] links to a non existent page-0 ? I created this ticket btw: #104

@coljung
Copy link

coljung commented Sep 28, 2016

One thing i just noticed is that the demo provided on this repo doesn't call the 'clickCallback' on load.

@terencechow
Copy link

Looks like if you use initialSelected it will invoke the click callback on load but if you use forceSelected it will not.

@ghost
Copy link

ghost commented Dec 2, 2016

@terencechow spot on, seems to be working on my end using forceSelected. The click callback is no longer being invoked on render.

@AdeleD
Copy link
Owner

AdeleD commented Dec 17, 2016

For your information, since react-paginate 3.0.0, the clickCallback (=onPageChange) isn't called anymore during initialization.

@mskec
Copy link
Contributor

mskec commented Jan 12, 2017

@AdeleD I can see here that it is still being called.
Would you be open to PR where I add bool flag whether to call it or not on initial render?

@AdeleD
Copy link
Owner

AdeleD commented Jan 12, 2017

Yes the callback is still called because: #116
If you don't want the callback being called during initialization, don't pass prop initialPage when you initialize the component.

<ReactPaginate previousLabel={"previous"}
               nextLabel={"next"}
               initialPage={1} // Remove this line
               pageCount={this.state.pageCount}
               onPageChange={this.handlePageClick} />

Is it OK for you this way?

@mskec
Copy link
Contributor

mskec commented Jan 13, 2017

By removing that line, callback will not be called. This works if you always have initialPage={1}, but won't work if you need to change initial page.

@AdeleD
Copy link
Owner

AdeleD commented Jan 13, 2017

Yes indeed. So, you're right, adding a boolean flag to change this behaviour if needed may be a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants