Skip to content

Instantly share code, notes, and snippets.

@zackferrofields
Last active February 12, 2018 20:22
Show Gist options
  • Save zackferrofields/d6db2d06755d75e03e684eb5babf676e to your computer and use it in GitHub Desktop.
Save zackferrofields/d6db2d06755d75e03e684eb5babf676e to your computer and use it in GitHub Desktop.
Stateless (almost) react scroll to on `componentDidMount`
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