GithubHelp home page GithubHelp logo

Comments (8)

petertdinh avatar petertdinh commented on May 15, 2024 7

Hi @AdeleD ,

Running into some problems trying to mess with the forceSelected prop. I don't entirely understand it. This is my approach right now.

this.state = { pageNum: 30, currentPage: 0,  forceSelected: 0 };

someMethod() {
  //force it to the first page
  this.setState({forceSelected: 0});
}

handlePageClick= (data) => {
  this.setState({currentPage: data.selected});
}

render() {
  <ReactPaginate clickCallback={this.handlePageClick}
                 pageNum={this.state.pageNum}
                 forceSelected={this.state.forceSelected} />
}

Unfortunately this isn't working for me. What can I do to force the selected page in the parent component?

from react-paginate.

cAstraea avatar cAstraea commented on May 15, 2024 2

Hello ,
Is it possible to update the selected page from another component ?
This is the problem I'm having http://recordit.co/TU5Wy2OI5W
I need the starting page to be at 1 when the ProductSearchForm component changes as it now remembers the last page it was on.
How can I approach this?

from react-paginate.

jraut avatar jraut commented on May 15, 2024 1

This is an issue if using react-router. If you push a navigation event to /paginated/10 and then cancel it in the route's onEnter (by replace(prevState.location.pathname);) the pagination updates altough forceSelected stays the same.

So selected in state does not follow the changes to forceSelected after handling onPageChange altough it receives new props.

from react-paginate.

AdeleD avatar AdeleD commented on May 15, 2024

Hi @phaeton2040,
You can pass the currently selected page to react-paginate thanks to the prop called forceSelected.

<ReactPaginate clickCallback={this.handlePageClick}
               pageNum={this.state.pageNum}
               forceSelected={4} />

from react-paginate.

phaeton2040 avatar phaeton2040 commented on May 15, 2024

@AdeleD , thnx for the answer. Actually it is already done. But it didn't work because I used version 1.0 where there was no 'shouldComponentUpdate' and because of this setting 'forceSelected' property had no effect on updates. I upgraded to 2.0 and now it works fine! Issue may be closed

from react-paginate.

nguyenbathanh avatar nguyenbathanh commented on May 15, 2024

Any implementation for this?

from react-paginate.

drellow avatar drellow commented on May 15, 2024

@petertdinh did you ever find a solution or workaround for forcing the page to update within the component?

from react-paginate.

WynnL avatar WynnL commented on May 15, 2024

For some reason every number but 0 works for the forcePage property. Is it just me or is this a bug?

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.