removeeventlistener

AddEventListener Event calling multiple times

安稳与你 提交于 2020-08-10 01:20:49
问题 I have a simple Cordova project with Angular Framework. I am using https://github.com/auctifera-josed/cordova-plugin-idynamo plugin to communicate with MagTek device. I am listening to the 'magtekEvent' on load of a particular screen to capture the data. Every time I go to other screen and come back to this screen I can see the event is triggering multiple times based on the number of time I visit this screen. I tried removing the event but nothing happened. Can anyone help me on how to stop

How do I window removeEventListener using React useEffect

百般思念 提交于 2020-05-28 12:05:06
问题 In React Hooks documents it is shown how to removeEventListener during the component's cleanup phase. https://reactjs.org/docs/hooks-reference.html#conditionally-firing-an-effect In my use case, I am trying to removeEventListener conditional to a state property of the functional component. Here's an example where the component is never unmounted but the event listener should be removed: function App () { const [collapsed, setCollapsed] = React.useState(true); React.useEffect( () => { if

Remove event listener that has been added using bind(this)

梦想的初衷 提交于 2020-05-13 04:35:09
问题 How do I remove the click listener I bound to window in the constructor below? I need it to listen on window , and I need access to the button instance inside it. class MyEl extends HTMLButtonElement { constructor() { super(); this.clickCount = 0; window.addEventListener('click', this.clickHandler.bind(this)); } clickHandler(e) { if (e.target === this) { this.textContent = `clicked ${++this.clickCount} times`; window.removeEventListener('click', this.clickHandler); } } disconnectedCallback()