@@ -26,7 +26,6 @@ import Divider from "@mui/material/Divider";
26
26
import OpenInNewOutlined from "@mui/icons-material/OpenInNewOutlined" ;
27
27
28
28
import { useDebouncedFunction } from "hooks/debounce" ;
29
- import { useEffectEvent } from "hooks/hookPolyfills" ;
30
29
31
30
export type PresetFilter = {
32
31
name : string ;
@@ -48,17 +47,18 @@ export const useFilter = ({
48
47
onUpdate,
49
48
searchParamsResult,
50
49
} : UseFilterConfig ) => {
50
+ const [ searchParams , setSearchParams ] = searchParamsResult ;
51
+
51
52
// Fully expect the initialValue functions to have some impurity (e.g. reading
52
53
// from localStorage during a render path). (Ab)using useState's lazy
53
54
// initialization mode to guarantee impurities only exist on mount. Pattern
54
55
// has added benefit of locking down initialValue and ignoring any accidental
55
56
// value changes on re-renders
56
57
const [ readonlyInitialQueryState ] = useState ( initialValue ) ;
57
58
58
- // React Router doesn't give setSearchParams a stable memory reference; need
59
- // extra logic to prevent on-mount effect from running too often
60
- const [ searchParams , setSearchParams ] = searchParamsResult ;
61
- const syncSearchParamsOnMount = useEffectEvent ( ( ) => {
59
+ // Sync the params with the value provided via the initialValue function;
60
+ // should behave only as an on-mount effect
61
+ useEffect ( ( ) => {
62
62
setSearchParams ( ( current ) => {
63
63
const currentFilter = current . get ( useFilterParamsKey ) ;
64
64
if ( currentFilter !== readonlyInitialQueryState ) {
@@ -67,11 +67,7 @@ export const useFilter = ({
67
67
68
68
return current ;
69
69
} ) ;
70
- } ) ;
71
-
72
- useEffect ( ( ) => {
73
- syncSearchParamsOnMount ( ) ;
74
- } , [ syncSearchParamsOnMount ] ) ;
70
+ } , [ setSearchParams , readonlyInitialQueryState ] ) ;
75
71
76
72
const update = ( newValues : string | FilterValues ) => {
77
73
const serialized =
0 commit comments