MCPcopy Create free account
hub / github.com/triggerdotdev/trigger.dev / useSearchParams

Function useSearchParams

apps/webapp/app/hooks/useSearchParam.ts:7–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5type Values = Record<string, string | string[] | undefined>;
6
7export function useSearchParams() {
8 const navigate = useNavigate();
9 const location = useOptimisticLocation();
10 const search = new URLSearchParams(location.search);
11
12 const set = useCallback(
13 (values: Values) => {
14 for (const [param, value] of Object.entries(values)) {
15 if (value === undefined) {
16 search.delete(param);
17 continue;
18 }
19
20 if (typeof value === "string") {
21 search.set(param, value);
22 continue;
23 }
24
25 search.delete(param);
26 for (const v of value) {
27 search.append(param, v);
28 }
29 }
30 },
31 [location, search]
32 );
33
34 const replace = useCallback(
35 (values: Values) => {
36 set(values);
37 navigate(`${location.pathname}?${search.toString()}`, { replace: true });
38 },
39 [location, search]
40 );
41
42 const del = useCallback(
43 (keys: string | string[]) => {
44 if (!Array.isArray(keys)) {
45 keys = [keys];
46 }
47 for (const key of keys) {
48 search.delete(key);
49 }
50 navigate(`${location.pathname}?${search.toString()}`, { replace: true });
51 },
52 [location, search]
53 );
54
55 const value = useCallback(
56 (param: string) => {
57 return search.get(param) ?? undefined;
58 },
59 [location, search]
60 );
61
62 const values = useCallback(
63 (param: string) => {
64 return search.getAll(param);

Callers 12

StatusDropdownFunction · 0.90
AppliedStatusFilterFunction · 0.90
EnvironmentsDropdownFunction · 0.90
AppliedEnvironmentFilterFunction · 0.90
TasksDropdownFunction · 0.90
AppliedTaskFilterFunction · 0.90
BulkActionsDropdownFunction · 0.90
AppliedBulkActionsFilterFunction · 0.90
CreatedDropdownFunction · 0.90
AppliedPeriodFilterFunction · 0.90
StatusesFunction · 0.90
EnvironmentsFunction · 0.90

Calls 6

useOptimisticLocationFunction · 0.90
toStringMethod · 0.80
deleteMethod · 0.65
setMethod · 0.45
getMethod · 0.45
getAllMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…