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.
npm install @render-props/scrollableyarn add @render-props/scrollable` or `npm i @render-props/scrollable`Usage
`js
import Scrollable from '@render-props/scrollable'const ScrollableBox = props => (
{
({
scrollRef,
scrollToX,
scrollToY,
scrollTo,
scrollHeight,
scrollWidth,
scrollY,
scrollX,
clientHeight,
clientWidth,
max,
direction,
distance,
}) => (
ref={scrollRef}
style={{
width: 300,
height: 300,
overflow: 'auto',
background: '#000'
}}
>
onClick={() => {
scrollTo(250, 500, {timing: p => p})
}}
style={{
position: 'absolute',
top: scrollY + 10,
left: scrollX + 10
}}
>
{JSON.stringify({
scrollRef,
scrollToX,
scrollToY,
scrollTo,
scrollHeight,
scrollWidth,
scrollY,
scrollX,
clientHeight,
clientWidth,
max,
direction,
distance,
}, null, 2)}
____
Props
- initialX {integer}
- initial position for the x coordinate
- initialY {integer}
- initial position for the y coordinate
- onScroll {function (state