Skip to content
Advertisement

Tag: ecmascript-6

React, setInterval behavior

Code Sample: https://codesandbox.io/s/romantic-wing-9yxw8?file=/src/App.tsx The code has two buttons – Start and Stop. Start calls a setInterval and saves interval id. Timer set to 1 second (1000 ms). Stop calls a clearInterval on the interval id. The interval id is declared outside the component. The interval callback function increments a counter and appends a called message to the UI. When I

WeakMap with event.target

Edit: turns out nothing is actually wrong with the second snippet (my real code). On one page it works, and on another it doesn’t. Yea for underlying errors. I’m creating a DOM element and giving that DOM element to a WeakMap as a key. Then, with JQuery event delegation/event listener, I’m trying to retrieve the saved key but it’s returning

Advertisement