Promise in UseEffect Umount

Viewed 245

I'm trying to stop a SignalR connection when a hook unmounts. The stop function is a Promise which needs to be resolved before the hook unmounts.

useEffect(() => {
  connection.start();

  return () => {
    connection.stop(); // Promise
  };
}, []);

But then I get this good ol' warning:

Warning: Can't perform a React state update on an unmounted component. This is a no-op...

I've tried extracting the stop functionality into an async function and calling that in unmount, but I get the same error. How can I stop the connection when the hook unmounts?

0 Answers
Related