Skip to content

Commit 8f532c3

Browse files
jdonelsonclaude
andcommitted
console: Drop unneeded useCallbacks from freshness params
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9541842 commit 8f532c3

1 file changed

Lines changed: 26 additions & 53 deletions

File tree

‎console/src/platform/freshness/useFreshnessParams.ts‎

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -104,63 +104,36 @@ export interface FreshnessParams {
104104
export function useFreshnessParams(): FreshnessParams {
105105
const [searchParams, setSearchParams] = useSearchParams();
106106

107-
const clear = React.useCallback(
108-
(key: string) => {
109-
setSearchParams(
110-
(prev) => {
111-
prev.delete(key);
112-
return prev;
113-
},
114-
{ replace: true },
115-
);
116-
},
117-
[setSearchParams],
118-
);
107+
const clear = (key: string) =>
108+
setSearchParams(
109+
(prev) => {
110+
prev.delete(key);
111+
return prev;
112+
},
113+
{ replace: true },
114+
);
119115

120-
const set = React.useCallback(
121-
(key: string, value: string) => {
122-
setSearchParams(
123-
(prev) => {
124-
prev.set(key, value);
125-
return prev;
126-
},
127-
{ replace: true },
128-
);
129-
},
130-
[setSearchParams],
131-
);
116+
const set = (key: string, value: string) =>
117+
setSearchParams(
118+
(prev) => {
119+
prev.set(key, value);
120+
return prev;
121+
},
122+
{ replace: true },
123+
);
132124

133-
// NOTE: these are not stable across a param change. They reach
134-
// `setSearchParams`, which react-router rebuilds whenever `searchParams`
135-
// changes, so changing any one param gives every setter a new identity. A
136-
// caller holding a timer must keep the setter in a ref rather than in a
137-
// dependency array, or an unrelated param moving will cancel its pending
138-
// call. See `useSettledThreshold`.
139-
const setClusterId = React.useCallback(
140-
(id: string) => set(CLUSTER_SEARCH_PARAM, id),
141-
[set],
142-
);
143-
const setThreshold = React.useCallback(
144-
(ms: number) => set(THRESHOLD_SEARCH_PARAM, String(ms)),
145-
[set],
146-
);
147-
const setTimePeriodMinutes = React.useCallback(
148-
(minutes: number) => set(TIME_PERIOD_SEARCH_PARAM_KEY, String(minutes)),
149-
[set],
150-
);
151-
const setPredicate = React.useCallback(
152-
(predicate: Predicate) => set(PREDICATE_SEARCH_PARAM, predicate),
153-
[set],
154-
);
125+
const setClusterId = (id: string) => set(CLUSTER_SEARCH_PARAM, id);
126+
const setThreshold = (ms: number) => set(THRESHOLD_SEARCH_PARAM, String(ms));
127+
const setTimePeriodMinutes = (minutes: number) =>
128+
set(TIME_PERIOD_SEARCH_PARAM_KEY, String(minutes));
129+
const setPredicate = (predicate: Predicate) =>
130+
set(PREDICATE_SEARCH_PARAM, predicate);
155131
// An empty selection is the absence of a filter, so it clears the param
156132
// rather than writing a sentinel nobody else would recognise.
157-
const setObjectTypes = React.useCallback(
158-
(types: string[]) =>
159-
types.length === 0
160-
? clear(OBJECT_TYPE_SEARCH_PARAM)
161-
: set(OBJECT_TYPE_SEARCH_PARAM, types.join(",")),
162-
[set, clear],
163-
);
133+
const setObjectTypes = (types: string[]) =>
134+
types.length === 0
135+
? clear(OBJECT_TYPE_SEARCH_PARAM)
136+
: set(OBJECT_TYPE_SEARCH_PARAM, types.join(","));
164137

165138
// Memoized on the raw param, which is a string and so compares by value.
166139
// Rebuilding it per render would hand every consuming `useMemo` a new array

0 commit comments

Comments
 (0)