A React component that watches for a scroll event
npm install react-scroll-activatorreact-scroll-activator watches for a scroll event inside of a container or on the window. When certain user-defined rules are met, it passes an activatedState prop to a render prop component, triggering whatever behavior the developer chooses on the child.

react-scroll-activator is a straightforward React component that watches for a scroll event inside any container or on the window. If a user scrolls, (and a series of conditions are met), the ScrollActivator component sends an activatedState prop to a render prop component, triggering the render prop component's behavior. - Installation
- Usage
- FAQ
- Inspiration
- Alternatives
- Contributors
- License
npm install react-scroll-activator
• Basic
You can either use the ScrollActivator component on the window, or on any container that scrolls.
#### On the window
``jsx
class StickyElement extends React.Component {
shouldComponentBeSticky = () => {
return window.scrollY > 120
}
isSticky = activatedState => {
if (activatedState === 'isActivated') {
return { position: 'fixed' }
} else {
return { position: 'relative' }
}
}
render () {
return (
{activatedState => (
Hi
)}
}
)
}
`
Let's say the modal's classname is .any-class-name:
`jsx
class StickyElement extends React.Component {
handleScrollCallback = (e, topOffset) => {
this.containerSelector = document.querySelector('.any-class-name')
return (
e.target.scrollTop >
this.containerSelector.getBoundingClientRect().top + topOffset
)
}
render () {
return (
`ScrollActivator
In this example, is wrapped around a StickyElement which is the component that will stick to the top of the container as the user scrolls. The ScrollActivator will pass activatedState to the child component, which the child component can then use to activate certain behavior. In the case of this example, the StickyElement will stick to the top of the component.
To actually make sure you are setting rules, add a handleScrollCallback function that resembles the one below to the class in which you are invoking ScrollActivator. You'll pass this to the ScrollActivator component onScroll`.