0

I know that we can bind pusher event like this

useEffect(() => {
    var channel = pusher.subscribe('my-channel');
    channel.bind('my-event', function(data) {
      alert(JSON.stringify(data));
    });
},[]);

But i can't find any ways to unbind it when the component unload. Is there some way to unbind it like this

useEffect(() => {
     var channel = pusher.subscribe('my-channel');
     channel.bind('my-event', function(data) {
       alert(JSON.stringify(data));
     });
     return () => channel.unbind('my-event');
 },[]);
Tạ Sinh Phúc
  • 123
  • 3
  • 10

1 Answers1

1

Pusher JS has an unbind feature, as documented at https://github.com/pusher/pusher-js#binding-to-events

// Remove all handlers for the `new-comment` event
channel.unbind('my-event')

If this is not working and you are encountering an error please edit your question to include the errors.

doydoy
  • 4,021
  • 3
  • 20
  • 33