From 536c2dadb37856a419502f0ca75c62142254c708 Mon Sep 17 00:00:00 2001 From: pem Date: Mon, 14 Oct 2019 09:53:11 +0200 Subject: [PATCH] Make dependencies explicit to make code easier to understand --- packages/ra-core/src/controller/useSortState.ts | 7 ++++--- .../ra-ui-materialui/src/input/AutocompleteArrayInput.tsx | 6 +++--- packages/ra-ui-materialui/src/layout/Notification.tsx | 2 +- packages/ra-ui-materialui/src/list/FilterButton.js | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/ra-core/src/controller/useSortState.ts b/packages/ra-core/src/controller/useSortState.ts index 5204f93dbab..8482f7a30cb 100644 --- a/packages/ra-core/src/controller/useSortState.ts +++ b/packages/ra-core/src/controller/useSortState.ts @@ -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); @@ -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, }; diff --git a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx index 9e0ea023cc5..9761ee79f32 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.tsx @@ -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 @@ -235,7 +235,7 @@ const AutocompleteArrayInput: FunctionComponent< setFilterValue(''); input.onChange(newSelectedItems.map(getChoiceValue)); }, - [getChoiceValue, input, selectedItems] + [getChoiceValue, input, selectedItems, setFilterValue] ); const handleDelete = useCallback( @@ -290,7 +290,7 @@ const AutocompleteArrayInput: FunctionComponent< handleFilterChange(''); input.onBlur(event); }, - [handleFilterChange, input] + [handleFilterChange, input, setFilterValue] ); const handleFocus = useCallback( diff --git a/packages/ra-ui-materialui/src/layout/Notification.tsx b/packages/ra-ui-materialui/src/layout/Notification.tsx index 2f77e7e45b1..5c81379a2d8 100644 --- a/packages/ra-ui-materialui/src/layout/Notification.tsx +++ b/packages/ra-ui-materialui/src/layout/Notification.tsx @@ -48,7 +48,7 @@ const Notification: React.FunctionComponent< const handleRequestClose = useCallback(() => { setOpen(false); - }, []); + }, [setOpen]); const handleExited = useCallback(() => { if (notification && notification.undoable) { diff --git a/packages/ra-ui-materialui/src/list/FilterButton.js b/packages/ra-ui-materialui/src/list/FilterButton.js index 4d782551113..63b7fea3404 100644 --- a/packages/ra-ui-materialui/src/list/FilterButton.js +++ b/packages/ra-ui-materialui/src/list/FilterButton.js @@ -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;