main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | var tslib_1 = require("tslib");
|
---|
| 4 | var react_1 = require("react");
|
---|
| 5 | var useRafState_1 = tslib_1.__importDefault(require("./useRafState"));
|
---|
| 6 | var util_1 = require("./misc/util");
|
---|
| 7 | var useScroll = function (ref) {
|
---|
| 8 | if (process.env.NODE_ENV === 'development') {
|
---|
| 9 | if (typeof ref !== 'object' || typeof ref.current === 'undefined') {
|
---|
| 10 | console.error('`useScroll` expects a single ref argument.');
|
---|
| 11 | }
|
---|
| 12 | }
|
---|
| 13 | var _a = useRafState_1.default({
|
---|
| 14 | x: 0,
|
---|
| 15 | y: 0,
|
---|
| 16 | }), state = _a[0], setState = _a[1];
|
---|
| 17 | react_1.useEffect(function () {
|
---|
| 18 | var handler = function () {
|
---|
| 19 | if (ref.current) {
|
---|
| 20 | setState({
|
---|
| 21 | x: ref.current.scrollLeft,
|
---|
| 22 | y: ref.current.scrollTop,
|
---|
| 23 | });
|
---|
| 24 | }
|
---|
| 25 | };
|
---|
| 26 | if (ref.current) {
|
---|
| 27 | util_1.on(ref.current, 'scroll', handler, {
|
---|
| 28 | capture: false,
|
---|
| 29 | passive: true,
|
---|
| 30 | });
|
---|
| 31 | }
|
---|
| 32 | return function () {
|
---|
| 33 | if (ref.current) {
|
---|
| 34 | util_1.off(ref.current, 'scroll', handler);
|
---|
| 35 | }
|
---|
| 36 | };
|
---|
| 37 | }, [ref]);
|
---|
| 38 | return state;
|
---|
| 39 | };
|
---|
| 40 | exports.default = useScroll;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.