use-scroll-to
Version:
A type safe React hook to handle scroll actions
24 lines (18 loc) • 985 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var react = require('react');
function useScrollTo(ref, options) {
return react.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]);
}
exports.default = useScrollTo;
//# sourceMappingURL=use-scroll-to.cjs.development.js.map