@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.
15 lines (12 loc) • 319 B
JavaScript
export default 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}
}