Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Mostly to fix warnings from eslint. The same will happen if you write like this
useEffect(() => { вызов dispatch }, [])
The dispatch function reference will be stable as long as the same store instance is being passed to the . Normally, that store instance never changes in an application.
However, the React hooks lint rules do not know that dispatch should be stable, and will warn that the dispatch variable should be added to dependency arrays for useEffect and useCallback. The simplest solution is to do just that:
eslint-plugin-react-hooks
does not know that the given function does not change its reference.
Can be configured via advanced configuration .
{
"rules": {
// ...
"react-hooks/exhaustive-deps": ["warn", {
"additionalHooks": "useDispatch|useOtherHookWhichWillDefinitelyNotChange"
}]
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question