Coding⏱️ 2 min read📅 2026-05-31

How to Fix: ReactJS: setTimeout() not working?

The setTimeout() function is not blocking the execution of the code. The state change happens immediately after the component has been rendered, which is before the timeout has expired.

Quick Answer: Use async/await or a callback function to delay the state update until the timeout has expired.

Having the code in mind, you are experiencing an issue with ReactJS where setTimeout() is not working as expected. This happens because of the way React handles state updates.

🔍 Why This Happens

  • The issue arises because the component is not re-rendered after the state change.

🔧 Proven Troubleshooting Steps

Method 1: Using the Callback Function

  1. Step 1: Replace setTimeout() with a callback function using the setState() method.

Method 2: Using Async/Await

  1. Step 1: Use async/await with the setTimeout() function and call the setState() method inside the callback.

✨ Wrapping Up

By applying these methods, you should be able to achieve the desired state change after 3 seconds in your ReactJS application.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions