I'm trying to get hot reloading to work with react 16.9.0 and react-redux 7.1.1.
This is my code where I want the loading of data (callback in useEffect()) called only once:
function Sidebar() {
const dispatch = useCallback(useDispatch(), []);
useEffect(() => {
console.info('useEffect');
dispatch(loadFields());
}, [dispatch]);
...
}
Despite using useCallback() to memoize the function, when I save a change to another JS file, the callback in useEffect() gets called again, reloading the fields.
If I changed the dependency of the useEffect() function from [dispatch] to just [], however, then it works the way I want and the callback in useEffect() does not get called on hot reload. But if I do this, the recommended React Eslint complains that I didn't include the dispatch dependency.
How do I make the linter happy, while getting hot reloading to work properly with useDispatch()?
Other symptoms:
- Using a static
['anything']also results in hot reloading not working; which is strange, because it should be equivalent to[].