socket.io-react-hook
socket.io-react-hook copied to clipboard
useSocketEvent with callback?
It looks like it would be fairly simple to add callback support to the useSocketEvent hook.
The API would then support something like this:
useSocketEvent('name-of-event', (response) => handleResponse(response));
It could be as simple as adding this effect:
useEffect(() => callback(lastMessage), [lastMessage]);
(Probably not wise to add callback to deps, because callback will change on every render)
Is there a good reason not to include this functionality?
useSocketEvent<string>(socket, "eventName", { onMessage });
There is a callback, onMessage