Skip to content

Commit

Permalink
Memoize default run scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 committed May 20, 2020
1 parent 0349740 commit dea39d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -73,6 +73,7 @@
"react": ">=16.8.0"
},
"dependencies": {
"memoize-one": "^5.1.1",
"tiny-invariant": "^1.1.0"
}
}
5 changes: 4 additions & 1 deletion src/index.js
Expand Up @@ -2,14 +2,17 @@ import {
useEffect, useLayoutEffect, useRef, useCallback,
} from 'react';
import invariant from 'tiny-invariant';
import memoize from 'memoize-one';
import { maxScrollTop } from './util';

// eslint-disable-next-line no-param-reassign
const defaultRunScroll = memoize((domRef) => (offset) => { domRef.current.scrollTop = offset; });
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;

export default (domRef, {
initialScroll = null,
inaccuracy = 0,
runScroll = (offset) => { domRef.current.scrollTop = offset; }, // eslint-disable-line no-param-reassign
runScroll = defaultRunScroll(domRef),
} = {}) => {
const wasScrolled = useRef(null);

Expand Down

0 comments on commit dea39d4

Please sign in to comment.