Skip to content

Instantly share code, notes, and snippets.

@danilowoz
Last active February 20, 2019 18:19
Show Gist options
  • Save danilowoz/3a028c700e3d5142f7f5a8dc071360b5 to your computer and use it in GitHub Desktop.
Save danilowoz/3a028c700e3d5142f7f5a8dc071360b5 to your computer and use it in GitHub Desktop.
import React, { Component } from "react"
import VisibilitySensor from "react-visibility-sensor"
const optsVisibily = {
minTopValue: 400,
partialVisibility: true,
scrollDelay: 100
}
const WithScroll = WrapComponent =>
class extends Component {
constructor(props) {
super(props)
this.state = {
visible: false
}
}
handle = event => {
if (event && !this.state.visible) {
this.setState({
visible: true
})
}
}
render() {
return (
<VisibilitySensor onChange={this.handle} {...optsVisibily}>
<WrapComponent isVisible={this.state.visible} {...this.props} />
</VisibilitySensor>
)
}
}
export default WithScroll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment