source: imaps-frontend/node_modules/react-use/lib/useSearchParam.js

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: 1.1 KB
RevLine 
[d565449]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var react_1 = require("react");
4var util_1 = require("./misc/util");
5var getValue = function (search, param) { return new URLSearchParams(search).get(param); };
6var useSearchParam = function (param) {
7 var location = window.location;
8 var _a = react_1.useState(function () { return getValue(location.search, param); }), value = _a[0], setValue = _a[1];
9 react_1.useEffect(function () {
10 var onChange = function () {
11 setValue(getValue(location.search, param));
12 };
13 util_1.on(window, 'popstate', onChange);
14 util_1.on(window, 'pushstate', onChange);
15 util_1.on(window, 'replacestate', onChange);
16 return function () {
17 util_1.off(window, 'popstate', onChange);
18 util_1.off(window, 'pushstate', onChange);
19 util_1.off(window, 'replacestate', onChange);
20 };
21 }, []);
22 return value;
23};
24var useSearchParamServer = function () { return null; };
25exports.default = util_1.isBrowser ? useSearchParam : useSearchParamServer;
Note: See TracBrowser for help on using the repository browser.