1.

Describe Timers in React Native Application ?

Answer»

Timers are an important and integral part of any application and React Native implements the browser timers.

Timers
 

  • setTimeout, clearTimeout

There may be business requirements to EXECUTE a certain PIECE of code after waiting for some time duration or after a delay setTimeout can be used in such cases, clearTimeout is simply used to CLEAR the timer that is started.

setTimeout(() => {yourFunction();}, 3000);
  • setInterval, clearInterval

setInterval is a method that calls a function or runs some code after specific intervals of time, as specified through the second parameter.

setInterval(() => {console.log('INTERVAL triggered');}, 1000);

A function or block of code that is bound to an interval EXECUTES until it is stopped. To stop an interval, we can use the clearInterval() method.

  • setImmediate, clearImmediate

Calling the function or execution as soon as possible.

var immediateID = setImmediate(function);// The below code displays the alert dialog immediately.var immediateId = setImmediate( () => { alert('Immediate Alert');}

clearImmediate  is used for Canceling the immediate actions that were set by setImmediate().

  • requestAnimationFrame, cancelAnimationFrame

It is the standard way to perform animations.

Calling a function to update an animation before the next animation frame.

var requestID = requestAnimationFrame(function);// The following code performs the animation.var requestId = requestAnimationFrame( () => { // animate something})

cancelAnimationFrame is used for Canceling the function that was set by requestAnimationFrame().



Discussion

No Comment Found