The eslint-plugin-react-hooks does not seem to recognize the dispatch function from useReducer when it is returned from another function. If we use that returned function in a useCallback or useEffect, the plugin warns that the function should be added to the dependency list.
As per React docs:
React guarantees that `dispatch` function identity is stable and won’t change on re-renders. This is why it’s safe to omit from the `useEffect` or `useCallback` dependency list.
React Hook React.useCallback has a missing dependency: 'forceUpdate'. Either include it or remove the dependency array. eslint(react-hooks/exhaustive-deps)
The expected behavior
There shouldn't be a warning, since useForceUpdate returns a dispatch function from useReducer.
The eslint-plugin-react-hooks does not seem to recognize the dispatch function from
useReducer
when it is returned from another function. If we use that returned function in auseCallback
oruseEffect
, the plugin warns that the function should be added to the dependency list.As per React docs:
React version: 16.12.0 eslint-plugin-react-hooks version: 2.5.1
Steps To Reproduce
useCallback
oruseEffect
The current behavior
There is a warning on
onClick
The expected behavior
There shouldn't be a warning, since
useForceUpdate
returns a dispatch function fromuseReducer
.