Skip to content

Commit

Permalink
Don't sync with redux either
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Jan 19, 2021
1 parent 787e696 commit df382f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 0 additions & 2 deletions packages/ra-core/src/controller/useListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,11 @@ const useListController = <RecordType extends Record = Record>(
);
}

const location = useLocation();
const translate = useTranslate();
const notify = useNotify();

const [query, queryModifiers] = useListParams({
resource,
location,
filterDefaultValues,
sort,
perPage,
Expand Down
20 changes: 11 additions & 9 deletions packages/ra-core/src/controller/useListParams.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useCallback, useMemo, useEffect } from 'react';
import { useCallback, useMemo, useEffect, useState } from 'react';
import { useSelector, useDispatch, shallowEqual } from 'react-redux';
import { parse, stringify } from 'query-string';
import lodashDebounce from 'lodash/debounce';
import set from 'lodash/set';
import pickBy from 'lodash/pickBy';
import { Location } from 'history';
import { useHistory } from 'react-router-dom';
import { useHistory, useLocation } from 'react-router-dom';

import queryReducer, {
SET_FILTER,
Expand All @@ -21,7 +20,6 @@ import removeKey from '../util/removeKey';

interface ListParamsOptions {
resource: string;
location: Location;
perPage?: number;
sort?: SortPayload;
// default value for a filter when displayed but not yet set
Expand Down Expand Up @@ -110,15 +108,16 @@ const defaultParams = {};
*/
const useListParams = ({
resource,
location,
filterDefaultValues,
sort = defaultSort,
perPage = 10,
debounce = 500,
syncWithLocation,
syncWithLocation = false,
}: ListParamsOptions): [Parameters, Modifiers] => {
const dispatch = useDispatch();
const location = useLocation();
const history = useHistory();
const [localParams, setLocalParams] = useState(defaultParams);
const params = useSelector(
(reduxState: ReduxState) =>
reduxState.admin.resources[resource]
Expand All @@ -130,10 +129,11 @@ const useListParams = ({
const requestSignature = [
location.search,
resource,
params,
syncWithLocation ? params : localParams,
filterDefaultValues,
JSON.stringify(sort),
perPage,
syncWithLocation,
];

const queryFromLocation = syncWithLocation
Expand All @@ -144,7 +144,7 @@ const useListParams = ({
() =>
getQuery({
queryFromLocation,
params,
params: syncWithLocation ? params : localParams,
filterDefaultValues,
sort,
perPage,
Expand Down Expand Up @@ -174,8 +174,10 @@ const useListParams = ({
),
})}`,
});
dispatch(changeListParams(resource, newParams));
} else {
setLocalParams(newParams);
}
dispatch(changeListParams(resource, newParams));
}, requestSignature); // eslint-disable-line react-hooks/exhaustive-deps

const setSort = useCallback(
Expand Down

0 comments on commit df382f8

Please sign in to comment.