I have this warning:
React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array react-hooks/exhaustive-deps
with this code:
import { useDispatch } from 'react-redux';
import openSocket from "socket.io-client";
import {populateCustomers} from './slices/CustomerSlice';
const ENDPOINT = config.ENDPOINT; //socket address
function App() {
const dispatch = useDispatch();
useEffect(() => {
const socket = openSocket(ENDPOINT);
//hydrate
socket.on("hydrateCustomers",data=>dispatch(populateCustomers(data)))
},[]);
the idea is that a socket is opened once, and on server events - data is dispatched from the response into the redux store.
I'm pretty sure I want an empty dependency array, as I only want this to run once... Is there a better way to handle this situation? or should I ignore this warning?