idev0085 / react-boilerplate

0 stars 0 forks source link

Describe Timers in React Native Application #114

Open idev0085 opened 2 years ago

idev0085 commented 2 years ago

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().