Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dependencies explicit to make code easier to understand #3816

Merged
merged 1 commit into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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