Skip to content

Commit 7f86cf8

Browse files
authored
Merge pull request #88 from Meberem/add-key
Allow data being shown to be "keyed"
2 parents e5e7402 + 580716a commit 7f86cf8

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,4 @@ name | type | description
8181
**pullDownToRefreshThreshold** | number | minimum distance the user needs to pull down to trigger the refresh, `default=100px`
8282
**refreshFunction** | function | this function will be called, it should return the fresh data that you want to show the user
8383
**initialScrollY** | number | set a scroll y position for the component to render with.
84+
**key** | string | the key for the current data set being shown, used when the same component can show different data sets at different times, `default=undefined`

app/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ export default class InfiniteScroll extends Component {
8282
}
8383

8484
componentWillReceiveProps(props) {
85-
// do nothing when dataLength is unchanged
86-
if (this.props.dataLength === props.dataLength) return;
85+
// do nothing when dataLength and key are unchanged
86+
if (this.props.key === props.key && this.props.dataLength === props.dataLength) return;
8787

8888
// update state when new data was sent in
8989
this.setState({
@@ -284,5 +284,6 @@ InfiniteScroll.propTypes = {
284284
pullDownToRefreshThreshold: PropTypes.number,
285285
refreshFunction: PropTypes.func,
286286
onScroll: PropTypes.func,
287-
dataLength: PropTypes.number.isRequired
287+
dataLength: PropTypes.number.isRequired,
288+
key: PropTypes.string
288289
};

0 commit comments

Comments
 (0)