React Hook React.useCallback has an unnecessary dependency: '...'. Either exclude it or remove the dependency array
Primary tabs
Line 29:8: React Hook React.useCallback has an unnecessary dependency: 'sortByPriceDown'. Either exclude it or remove the dependency array. Outer scope values like 'sortByPriceDown' aren't valid dependencies because mutating them doesn't re-render the component react-hooks/exhaustive-deps
Для кода:
import { sortByPriceUp, sortByPriceDown } from '@app-actions/goodsActions'; import { useDispatch } from 'react-redux'; export default function GoodsListTable(props: GoodsListTablePropsType) { const dispatch = useDispatch(); const onSortByPriceUp = React.useCallback(()=> { dispatch(sortByPriceUp); }, [sortByPriceUp, dispatch]);
-- почему при этом не ругается для dispatch?
Ответ
Судя по всему из-за того, что dispatch у нас получается в коде динамически:
const dispatch = useDispatch();
-- через вызов функции, а не импортируется напрямую снаружи.
- Log in to post comments
- 947 reads