Last active
February 12, 2018 20:22
-
-
Save zackferrofields/d6db2d06755d75e03e684eb5babf676e to your computer and use it in GitHub Desktop.
Stateless (almost) react scroll to on `componentDidMount`
This file contains hidden or 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 { createElement } from 'react'; | |
import { compose } from 'ramda'; | |
import { lifecycle, withProps } from 'recompose'; | |
const enhance = compose( | |
lifecycle({ componentDidMount() { | |
this.refs.node.scrollIntoView({block: 'end', behavior: 'smooth'}); | |
} }), | |
withProps({ ref: 'node' }), | |
); | |
const autoScroll = Component => ({ ref, ...props }) => | |
createElement('div', { ref }, createElement(Component, props)); | |
export default compose(enhance, autoScroll); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment