UNPKG

use-scroll-to

Version:

A type safe React hook to handle scroll actions

20 lines (16 loc) 892 B
import { useCallback } from 'react'; function useScrollTo(ref, options) { return useCallback(function () { var _ref$current, _window; var refOffSetTop = (ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.offsetTop) || 0; var minus = (options === null || options === void 0 ? void 0 : options.minus) ? Math.abs(options.minus) : 0; var plus = (options === null || options === void 0 ? void 0 : options.plus) ? Math.abs(options.plus) : 0; var behavior = (options === null || options === void 0 ? void 0 : options.behavior) || 'smooth'; (_window = window) === null || _window === void 0 ? void 0 : _window.scroll({ top: refOffSetTop - minus + plus, behavior: behavior }); }, [ref, options]); } export default useScrollTo; //# sourceMappingURL=use-scroll-to.esm.js.map