Skip to content

Tag: javascript

Define getter using defineProperty

In our application we compress our JavaScript classes using UglifyJS which doesn’t support being able to compress syntax like onBlur = (event) => {} as it returns Unexpected token: operator (=). To solve this problem we have used the following function to define them: And then we use it inside our co…

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 i…