File tree Expand file tree Collapse file tree
packages/platform/src/app/hooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,17 +16,19 @@ const KEY = 'query';
1616export function useQueryParams < T extends { } > (
1717 initParams : Partial < T >
1818) : [ T , ( newQuery : T | ( ( draft : T ) => void ) , options ?: NavigateOptions ) => void ] {
19- const initURLSearchParams = useMemo (
20- ( ) => new URLSearchParams ( { [ KEY ] : JSURL . stringify ( initParams ) } ) ,
21- // eslint-disable-next-line react-hooks/exhaustive-deps
22- [ ]
23- ) ;
24- const [ searchParams , setSearchParams ] = useSearchParams ( initURLSearchParams ) ;
25- const queryValues = useMemo < T > ( ( ) => JSURL . parse ( searchParams . get ( KEY ) ) , [ searchParams ] ) ;
19+ const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
20+ // eslint-disable-next-line react-hooks/exhaustive-deps
21+ const queryValues = useMemo < T > ( ( ) => ( searchParams . get ( KEY ) ? JSURL . parse ( searchParams . get ( KEY ) ) : initParams ) , [ searchParams ] ) ;
2622
2723 const setQueryValues = useEventCallback ( ( newValue : T | ( ( draft : T ) => void ) , options ?: NavigateOptions ) => {
2824 const newQueryValues = isFunction ( newValue ) ? produce ( queryValues , newValue ) : newValue ;
29- setSearchParams ( new URLSearchParams ( { [ KEY ] : JSURL . stringify ( newQueryValues ) } ) , { replace : true , ...options } ) ;
25+ setSearchParams (
26+ ( prev ) => {
27+ prev . set ( KEY , JSURL . stringify ( newQueryValues ) ) ;
28+ return prev ;
29+ } ,
30+ { replace : true , ...options }
31+ ) ;
3032 } ) ;
3133 return [ queryValues , setQueryValues ] ;
3234}
You can’t perform that action at this time.
0 commit comments