MCPcopy
hub / github.com/epicweb-dev/react-hooks / setGlobalSearchParams

Function setGlobalSearchParams

shared/utils.tsx:9–27  ·  view source on GitHub ↗
(
	params: Record<string, string | null>,
	options: { replace?: boolean } = {},
)

Source from the content-addressed store, hash-verified

7 * @returns {URLSearchParams} - The updated search parameters.
8 */
9export function setGlobalSearchParams(
10 params: Record<string, string | null>,
11 options: { replace?: boolean } = {},
12) {
13 const searchParams = new URLSearchParams(window.location.search)
14 for (const [key, value] of Object.entries(params)) {
15 if (!value) searchParams.delete(key)
16 else searchParams.set(key, value)
17 }
18 const newUrl = [window.location.pathname, searchParams.toString()]
19 .filter(Boolean)
20 .join('?')
21 if (options.replace) {
22 window.history.replaceState({}, '', newUrl)
23 } else {
24 window.history.pushState({}, '', newUrl)
25 }
26 return searchParams
27}

Callers 10

AppFunction · 0.90
AppFunction · 0.90
AppFunction · 0.90
AppFunction · 0.90
FormFunction · 0.90
FormFunction · 0.90
FormFunction · 0.90
FormFunction · 0.90
FormFunction · 0.90
FormFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…