source: imaps-frontend/node_modules/react-use/lib/useHash.js@ d565449

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: 990 bytes
RevLine 
[d565449]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.useHash = void 0;
4var tslib_1 = require("tslib");
5var react_1 = require("react");
6var useLifecycles_1 = tslib_1.__importDefault(require("./useLifecycles"));
7var util_1 = require("./misc/util");
8/**
9 * read and write url hash, response to url hash change
10 */
11var 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};
28exports.useHash = useHash;
Note: See TracBrowser for help on using the repository browser.