Skip to content

Commit

Permalink
Merge pull request #3816 from marmelab/update-useCallback-dependencies
Browse files Browse the repository at this point in the history
Make dependencies explicit to make code easier to understand
  • Loading branch information
djhi authored Oct 14, 2019
2 parents a887d3e + 536c2da commit 90034e4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
7 changes: 4 additions & 3 deletions packages/ra-core/src/controller/useSortState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const defaultSort = { field: 'id', order: 'DESC' };
* @param {string} initialSort.order The initial sort order
* @returns {SortProps} The sort props
*/

export default (initialSort: Sort = defaultSort): SortProps => {
const [sort, dispatch] = useReducer(sortReducer, initialSort);
const isFirstRender = useRef(true);
Expand All @@ -116,17 +117,17 @@ export default (initialSort: Sort = defaultSort): SortProps => {
return {
setSort: useCallback(
(sort: Sort) => dispatch({ type: 'SET_SORT', payload: { sort } }),
[]
[dispatch]
),
setSortField: useCallback(
(field: string) =>
dispatch({ type: 'SET_SORT_FIELD', payload: { field } }),
[]
[dispatch]
),
setSortOrder: useCallback(
(order: string) =>
dispatch({ type: 'SET_SORT_ORDER', payload: { order } }),
[]
[dispatch]
),
sort,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const AutocompleteArrayInput: FunctionComponent<
setFilter(value);
}
},
[setFilter]
[setFilter, setFilterValue]
);

// We must reset the filter every time the value changes to ensure we
Expand Down Expand Up @@ -235,7 +235,7 @@ const AutocompleteArrayInput: FunctionComponent<
setFilterValue('');
input.onChange(newSelectedItems.map(getChoiceValue));
},
[getChoiceValue, input, selectedItems]
[getChoiceValue, input, selectedItems, setFilterValue]
);

const handleDelete = useCallback(
Expand Down Expand Up @@ -290,7 +290,7 @@ const AutocompleteArrayInput: FunctionComponent<
handleFilterChange('');
input.onBlur(event);
},
[handleFilterChange, input]
[handleFilterChange, input, setFilterValue]
);

const handleFocus = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/layout/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Notification: React.FunctionComponent<

const handleRequestClose = useCallback(() => {
setOpen(false);
}, []);
}, [setOpen]);

const handleExited = useCallback(() => {
if (notification && notification.undoable) {
Expand Down
6 changes: 3 additions & 3 deletions packages/ra-ui-materialui/src/list/FilterButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ const FilterButton = ({
setOpen(true);
anchorEl.current = event.currentTarget;
},
[anchorEl]
[anchorEl, setOpen]
);

const handleRequestClose = useCallback(() => {
setOpen(false);
}, []);
}, [setOpen]);

const handleShow = useCallback(
({ source, defaultValue }) => {
showFilter(source, defaultValue);
setOpen(false);
},
[showFilter]
[showFilter, setOpen]
);

if (hiddenFilters.length === 0) return null;
Expand Down

0 comments on commit 90034e4

Please sign in to comment.