Saturday, November 15, 2025
Latest:
  • What are the main differences between ApplicationContext and BeanFactory?
  • German B1 Word list
  • How does Lazy annotation work in Spring?
  • How Spring framework resolves circular dependencies?
  • German Pronouns with Nominative, Accusative, and Dative cases
Upokary

Upokary

Quality information

  • Health
  • Life
  • Fashion
  • Food
  • Code
  • English
  • বাংলা
Technology 

Why useState is asynchronous in ReactJS?

Published: January 1, 2021Last updated: July 31, 2021 asynchronous, useState

The main reason for asynchronous useState is the closure scope around an immutable const value.

We can not do await setState() to make it synchronous. On the very first rendering props and state are assumed to be unchanging.

Treat this.state as if it were immutable.

To achieve this we use const keyword with useState hook.

const [state, setState] = useState('initial');

Between the renders, the value might be different. For a particular render, the value remains constant and of course inside the closures.

Reference:
  • https://stackoverflow.com/questions/54069253/usestate-set-method-not-reflecting-change-immediately

You May Also Like

ERROR 1067 (42000): Invalid default value for ‘created_at’

July 23, 2021 beroza

How to Integrate the Material UI Data Grid in React?

January 10, 2022 beroza

Free disk space related useful command in Linux

March 7, 2019 beroza

What is Cross-Site Request Forgery (CSRF)? Why CSRF is important?

September 4, 2022 beroza

Unable to load script from assets index.android.bundle

December 11, 2018 beroza

JavaScript tips for problem solving

June 11, 2023 beroza

Write a program to check if all characters have equal number of occurrences

June 9, 2022 beroza

Webpack related important links

August 11, 2022 beroza

ReferenceError: localStorage is not defined

April 10, 2021 beroza

Why Upokary?

Upokary.com is a useful application in everyday life. It provides very handy information regarding every aspect of life. Each and every tip of upokary.com is meant to make life better.

Upokary tools

  • Youtube thumbnail
  • Youtube video downloader

Useful Links

  • Handy code
  • Technology
  • People
  • Programming
  • Quote
  • Travel
  • WordPress
  • IELTS
  • Kids

Pages

  • Sitemap
  • Privacy policy
  • About us
  • Contact us

Support

For any kind of query or question please drop a message in the following email: upokary@gmail.com
Copyright © 2025 Upokary. All rights reserved.