source: imaps-frontend/node_modules/react-use/esm/useSearchParam.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: 982 bytes
Line 
1import { useEffect, useState } from 'react';
2import { isBrowser, off, on } from './misc/util';
3var getValue = function (search, param) { return new URLSearchParams(search).get(param); };
4var 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};
22var useSearchParamServer = function () { return null; };
23export default isBrowser ? useSearchParam : useSearchParamServer;
Note: See TracBrowser for help on using the repository browser.