Last active
February 20, 2019 18:19
-
-
Save danilowoz/3a028c700e3d5142f7f5a8dc071360b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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