ably-js icon indicating copy to clipboard operation
ably-js copied to clipboard

Right way to clean up listeners

Open yishay-at-bay opened this issue 8 months ago • 1 comments

Hi

If I use React

useEffect(() => {
    const connectionChangeCallback = (
      connectionState: ConnectionStateChange,
    ) => {
      ...
    };

    client?.connection?.on(connectionChangeCallback);

    return () => client?.connection?.off(connectionChangeCallback);
  }, [client]);

Does that the right way to clean up that listener when the component unmounts?

┆Issue is synchronized with this Jira Task by Unito

yishay-at-bay avatar Jun 24 '24 20:06 yishay-at-bay