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

Add public method reset to force restart pagination #219

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,12 @@ You can define a custom `parentNode` element to base the scroll calulations on.
| `threshold` | `Number` | `250` | The distance in pixels before the end of the items that will trigger a call to `loadMore`.|
| `useCapture` | `Boolean` | `false` | Proxy to the `useCapture` option of the added event listeners.|
| `useWindow` | `Boolean` | `true` | Add scroll listeners to the window, or else, the component's `parentNode`.|

### Public Methods

##### reset
Forcefully reset the local page based on `pageStart`. If the prop `initialLoad` is provided, force call `loadMore` with the start page.

This may be appropriate if the api that inserts data in the list is reset, and the next page will be the initial page and not the last page known by InfiniteScroll. This is very common in listings with InfiniteScroll and search input.

For the access public methods use `ref` prop.
8 changes: 8 additions & 0 deletions src/InfiniteScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ export default class InfiniteScroll extends Component {
this.detachMousewheelListener();
}

reset() {
this.pageLoaded = this.props.pageStart;
marlonmleite marked this conversation as resolved.
Show resolved Hide resolved

if (this.props.initialLoad) {
this.scrollListener();
}
}

isPassiveSupported() {
let passive = false;

Expand Down