whatsapp_btn
whatsapp_btn Chat With Us

Home >> React Native Q&A >> setTimeout in React Native

setTimeout in React Native

  2 min read
setTimeout in React Native

Here you can see a code that crashes the app and shows the error that this. setState is not a function.

You see this is a keyword that developers can’t use inside a callback method of setTimeout. JavaScript’s keyword does not directly refer to the component’s instance when a regular function is used as a callback method by using the setTimeout function. It shows that a function can be anything: a window, a button, or any object. This problem happens because the setState function is not available to be used globally.

Now, you can see that developers can follow these two approaches to overcome this issue.

1. Using ‘Bind’ Keyword

You see the bind keyword needs to be binded inside the function of this specific class and an example is given below.

2. Using arrow Functions (ES6+)

In this, you just have to implement arrow functions according to the standards of ES6+ to resolve all your requirements. However, the arrow functions do not have this keyword bound to them. That’s why the arrow function is always represented by the keyword “this” in arrow functions and the example is given below.

Tagline Infotech
Tagline Infotech a well-known provider of IT services, is deeply committed to assisting other IT professionals in all facets of the industry. We continuously provide comprehensive and high-quality content and products that give customers a strategic edge and assist them in improving, expanding, and taking their business to new heights by using the power of technology. You may also find us on LinkedIn, Instagram, Facebook and Twitter.

Related Posts :

contact-us-bg

Our Global Presence

India (HQ)

Digital Valley, 423, Apple Square, beside Lajamni Chowk, Mota Varachha, Surat, Gujarat 394101

 +91 9913 808 285

U.S.A

1133 Sampley Ln Leander, Texas, 78641

United Kingdom

52 Godalming Avenue, wallington, London - SM6 8NW