title: React web3 contract events removing listener is not possible
body: <p>I am trying to create a custom hook which listens to my web3 contract events and unbinds when I change my account or network. Nonetheless it executes twice when I switch my account back and forth. Except this it works fine but for any reasons it does not remove the listener.</p>
  <p>I have also tried removing the listener before I add it but still it will only be added and so on execute more then once.</p>
  <pre><code>const EVENT_OPTIONS = {
      fromBlock: &quot;latest&quot;,
  };
  
  export const useEvent = (event, handler) =&gt; {
      useEffect(() =&gt; {
          if (!event) return;
          event(EVENT_OPTIONS).addListener(&quot;data&quot;, handler);
  
          return () =&gt; {
              //This gets executed but the event will not be removed
              // (Executed when the metamask network changes)
              event(EVENT_OPTIONS).removeListener(&quot;data&quot;, handler);
          }
      }, [event])
  }
  
  // ----- Example for useEvent:
  
  export const useOnNewRound = (callback) =&gt; {
      const contract = useContractWSS(); // returns websocket contract
      
      const sortData = useCallback((data) =&gt; {
          // do something with data...
          callback(data)
      }, [])
       
      useEvent(contract?.events.NewRound, sortData); //Pass event and handler function
  }
  </code></pre>