GithubHelp home page GithubHelp logo

Comments (13)

donperi avatar donperi commented on May 14, 2024 2

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

from react-paginate.

terencechow avatar terencechow commented on May 14, 2024 2

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

from react-paginate.

AdeleD avatar AdeleD commented on May 14, 2024 1

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

from react-paginate.

AdeleD avatar AdeleD commented on May 14, 2024

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.

from react-paginate.

jzlxiaohei avatar jzlxiaohei commented on May 14, 2024

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

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

from react-paginate.

donperi avatar donperi commented on May 14, 2024

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.

from react-paginate.

coljung avatar coljung commented on May 14, 2024

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

from react-paginate.

coljung avatar coljung commented on May 14, 2024

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

from react-paginate.

 avatar commented on May 14, 2024

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

from react-paginate.

AdeleD avatar AdeleD commented on May 14, 2024

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

from react-paginate.

mskec avatar mskec commented on May 14, 2024

@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?

from react-paginate.

AdeleD avatar AdeleD commented on May 14, 2024

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?

from react-paginate.

mskec avatar mskec commented on May 14, 2024

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.

from react-paginate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.