Skip to content

Commit

Permalink
add isRestart to check for startover
Browse files Browse the repository at this point in the history
add componentWillReceiveProps to check props and detach when hasMore is false
  • Loading branch information
dantzchan committed May 22, 2017
1 parent ca66c1a commit 506138f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/InfiniteScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class InfiniteScroll extends Component {
PropTypes.array,
]).isRequired,
loader: PropTypes.object,
isRestart: PropTypes.bool,
};

static defaultProps = {
Expand All @@ -31,27 +32,35 @@ export default class InfiniteScroll extends Component {
isReverse: false,
useCapture: false,
loader: null,
isRestart: false,
};

constructor(props) {
super(props);

this.scrollListener = this.scrollListener.bind(this);
}

componentDidMount() {
this.pageLoaded = this.props.pageStart;
this.attachScrollListener();
if(this.props.hasMore)
this.attachScrollListener()
}

componentDidUpdate() {
this.attachScrollListener();
componentWillReceiveProps(nextProps) {
this.props = nextProps;
if(!this.props.hasMore)
this.detachScrollListener();
if(this.props.isRestart)
this.pageLoaded = this.props.pageStart;
}

componentDidUpdate() {
if(this.props.hasMore)
this.attachScrollListener();
}
componentWillUnmount() {
this.detachScrollListener();
}

// Set a defaut loader for all your `InfiniteScroll` components
setDefaultLoader(loader) {
this.defaultLoader = loader;
Expand Down Expand Up @@ -137,6 +146,7 @@ export default class InfiniteScroll extends Component {
threshold,
useCapture,
useWindow,
isRestart,
...props
} = this.props;

Expand Down

0 comments on commit 506138f

Please sign in to comment.