Skip to content

Commit

Permalink
Use normal store instead of React state with disabled location sync
Browse files Browse the repository at this point in the history
This change is to continue using the normal React Admin store (local storage by default) when `disableSyncWithLocation` is used.

Skips the `navigate` call and directly calls `setParam`
  • Loading branch information
btbenedi authored Dec 22, 2022
1 parent ce4f4de commit a5fd4cc
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/ra-core/src/controller/list/useListParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useMemo, useEffect, useState, useRef } from 'react';
import { useCallback, useMemo, useEffect, useRef } from 'react';
import { parse, stringify } from 'query-string';
import lodashDebounce from 'lodash/debounce';
import pickBy from 'lodash/pickBy';
Expand Down Expand Up @@ -87,7 +87,6 @@ export const useListParams = ({
}: ListParamsOptions): [Parameters, Modifiers] => {
const location = useLocation();
const navigate = useNavigate();
const [localParams, setLocalParams] = useState(defaultParams);
const [params, setParams] = useStore(storeKey, defaultParams);
const tempParams = useRef<ListParams>();
const isMounted = useIsMounted();
Expand All @@ -96,7 +95,7 @@ export const useListParams = ({
location.search,
resource,
storeKey,
JSON.stringify(disableSyncWithLocation ? localParams : params),
JSON.stringify(params),
JSON.stringify(filterDefaultValues),
JSON.stringify(sort),
perPage,
Expand All @@ -111,7 +110,7 @@ export const useListParams = ({
() =>
getQuery({
queryFromLocation,
params: disableSyncWithLocation ? localParams : params,
params,
filterDefaultValues,
sort,
perPage,
Expand Down Expand Up @@ -142,7 +141,7 @@ export const useListParams = ({
// schedule side effects for next tick
setTimeout(() => {
if (disableSyncWithLocation) {
setLocalParams(tempParams.current);
setParams(tempParams.current);
} else {
// the useEffect above will apply the changes to the params in the store
navigate(
Expand Down

0 comments on commit a5fd4cc

Please sign in to comment.