@render-props/scrollable
Version:
A state container which provides an interface for listening to the scroll event of its child component and providing valuable data about direction, distance, and more. It also provides convenience functions for scrollTo with optional animation.
23 lines (18 loc) • 387 B
JavaScript
exports.__esModule = true
exports.default = getDistance
function getDistance(prevState, nextState) {
const x = nextState.scrollX - prevState.scrollX
const y = nextState.scrollY - prevState.scrollY
if (
prevState.distance &&
x === prevState.distance.x &&
y === prevState.distance.y
) {
return prevState.distance
}
return {
x,
y,
}
}