MCPcopy Index your code
hub / github.com/coder/coder / useSearchParamsKey

Function useSearchParamsKey

site/src/hooks/useSearchParamsKey.ts:16–41  ·  view source on GitHub ↗
(
	config: UseSearchParamsKeyConfig,
)

Source from the content-addressed store, hash-verified

14}>;
15
16export const useSearchParamsKey = (
17 config: UseSearchParamsKeyConfig,
18): UseSearchParamKeyResult => {
19 // Cannot use function update form for setSearchParams, because by default, it
20 // will always be linked to innerSearchParams, ignoring the config's params
21 const [innerSearchParams, setSearchParams] = useSearchParams();
22
23 const {
24 key,
25 searchParams = innerSearchParams,
26 defaultValue = "",
27 replace = true,
28 } = config;
29
30 return {
31 value: searchParams.get(key) ?? defaultValue,
32 setValue: (newValue) => {
33 searchParams.set(key, newValue);
34 setSearchParams(searchParams, { replace });
35 },
36 deleteValue: () => {
37 searchParams.delete(key);
38 setSearchParams(searchParams, { replace });
39 },
40 };
41};

Callers 6

TasksSidebarFunction · 0.90
useResourcesNavFunction · 0.90
WorkspaceFunction · 0.90
TasksPageFunction · 0.90
NotificationsPageFunction · 0.90

Calls 2

getMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected