main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
990 bytes
|
Rev | Line | |
---|
[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | exports.useHash = void 0;
|
---|
| 4 | var tslib_1 = require("tslib");
|
---|
| 5 | var react_1 = require("react");
|
---|
| 6 | var useLifecycles_1 = tslib_1.__importDefault(require("./useLifecycles"));
|
---|
| 7 | var util_1 = require("./misc/util");
|
---|
| 8 | /**
|
---|
| 9 | * read and write url hash, response to url hash change
|
---|
| 10 | */
|
---|
| 11 | var useHash = function () {
|
---|
| 12 | var _a = react_1.useState(function () { return window.location.hash; }), hash = _a[0], setHash = _a[1];
|
---|
| 13 | var onHashChange = react_1.useCallback(function () {
|
---|
| 14 | setHash(window.location.hash);
|
---|
| 15 | }, []);
|
---|
| 16 | useLifecycles_1.default(function () {
|
---|
| 17 | util_1.on(window, 'hashchange', onHashChange);
|
---|
| 18 | }, function () {
|
---|
| 19 | util_1.off(window, 'hashchange', onHashChange);
|
---|
| 20 | });
|
---|
| 21 | var _setHash = react_1.useCallback(function (newHash) {
|
---|
| 22 | if (newHash !== hash) {
|
---|
| 23 | window.location.hash = newHash;
|
---|
| 24 | }
|
---|
| 25 | }, [hash]);
|
---|
| 26 | return [hash, _setHash];
|
---|
| 27 | };
|
---|
| 28 | exports.useHash = useHash;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.