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

Fix null error on removing children #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,5 @@
"react",
"react-component",
"infinite-scroll"
],
"engines": {
"node": "^9.6.1 || ^8.0.0",
"npm": "^5.6.0"
}
]
}
16 changes: 8 additions & 8 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export default class extends Component {
onReachLeft
} = this.props

const leftEdge = firstChild.offsetLeft
const rightEdge = lastChild.offsetLeft + lastChild.offsetWidth
const leftEdge = firstChild && firstChild.offsetLeft
const rightEdge = lastChild && (lastChild.offsetLeft + lastChild.offsetWidth)
const scrolledLeft = scrollLeft + offsetLeft
const scrolledRight = scrolledLeft + offsetWidth

if (scrolledRight >= rightEdge) {
if (rightEdge && scrolledRight >= rightEdge) {
onReachRight()
} else if (scrolledLeft <= leftEdge) {
} else if (leftEdge && scrolledLeft <= leftEdge) {
onReachLeft()
}
}
Expand All @@ -93,14 +93,14 @@ export default class extends Component {
onReachBottom
} = this.props

const topEdge = firstChild.offsetTop
const bottomEdge = lastChild.offsetTop + lastChild.offsetHeight
const topEdge = firstChild && firstChild.offsetTop
const bottomEdge = lastChild && (lastChild.offsetTop + lastChild.offsetHeight)
const scrolledUp = scrollTop + offsetTop
const scrolledDown = scrolledUp + offsetHeight

if (scrolledDown >= bottomEdge) {
if (bottomEdge && scrolledDown >= bottomEdge) {
onReachBottom()
} else if (scrolledUp <= topEdge) {
} else if (topEdge && scrolledUp <= topEdge) {
onReachTop()
}
}
Expand Down