Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return pathname || {};
}, [location.search, location.pathname, locationIsObject, windowIsDefined]);
}
// read in the encoded string value
const encodedValue = rawQuery[name];
// note that we use the stringified encoded value since the encoded
// value may be an array that is recreated if a different query param
// changes. It is sufficient to use this instead of encodedValue in
// the useMemo dependency array since it will change any time the actual
// meaningful value of encodedValue changes.
const arraySafeEncodedValue =
encodedValue instanceof Array
? stringify({ [name]: encodedValue })
: encodedValue;
// decode if the encoded value has changed, otherwise
// re-use memoized value
const decodedValue = React.useMemo(() => {
if (encodedValue == null) {
return undefined;
}
return paramConfig.decode(encodedValue);
}, [arraySafeEncodedValue, paramConfig]); // eslint-disable-line react-hooks/exhaustive-deps
// create the setter, memoizing via useCallback
const setValue = React.useCallback(
(newValue: D, updateType?: UrlUpdateType) => {
const newEncodedValue = paramConfig.encode(newValue);
export function makeMockLocation(query: EncodedQueryWithNulls): Location {
const queryStr = stringify(query);
return {
protocol: 'http:',
host: 'localhost',
pathname: '/',
search: queryStr.length ? `?${queryStr}` : '',
} as Location;
}