1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | var react_1 = require("react");
|
---|
4 | var util_1 = require("./misc/util");
|
---|
5 | var getValue = function (search, param) { return new URLSearchParams(search).get(param); };
|
---|
6 | var 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 | };
|
---|
24 | var useSearchParamServer = function () { return null; };
|
---|
25 | exports.default = util_1.isBrowser ? useSearchParam : useSearchParamServer;
|
---|