1 | import { useEffect, useState } from 'react';
|
---|
2 | import { isBrowser, off, on } from './misc/util';
|
---|
3 | var getValue = function (search, param) { return new URLSearchParams(search).get(param); };
|
---|
4 | var useSearchParam = function (param) {
|
---|
5 | var location = window.location;
|
---|
6 | var _a = useState(function () { return getValue(location.search, param); }), value = _a[0], setValue = _a[1];
|
---|
7 | useEffect(function () {
|
---|
8 | var onChange = function () {
|
---|
9 | setValue(getValue(location.search, param));
|
---|
10 | };
|
---|
11 | on(window, 'popstate', onChange);
|
---|
12 | on(window, 'pushstate', onChange);
|
---|
13 | on(window, 'replacestate', onChange);
|
---|
14 | return function () {
|
---|
15 | off(window, 'popstate', onChange);
|
---|
16 | off(window, 'pushstate', onChange);
|
---|
17 | off(window, 'replacestate', onChange);
|
---|
18 | };
|
---|
19 | }, []);
|
---|
20 | return value;
|
---|
21 | };
|
---|
22 | var useSearchParamServer = function () { return null; };
|
---|
23 | export default isBrowser ? useSearchParam : useSearchParamServer;
|
---|