Sunday, October 12, 2025
Latest:
  • German Pronouns with Nominative, Accusative, and Dative cases
  • German articles for the nominative, accusative, and dative cases
  • Der kleine Vogel und die Sonne
  • German alphabet pronunciation
  • Command design pattern
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

Query posts with featured image in WordPress.

January 4, 2020 beroza

How to map all quotation marks to double quote?

June 8, 2022 beroza

What are the benefits of Docker containers?

July 18, 2019 beroza

How to set exact path along with dynamic param using react router?

March 6, 2020 beroza

Difference between Arrays.asList(array) and new ArrayList(Arrays.asList(array)) in Java

May 26, 2020 beroza

Uncaught ReferenceError: $ is not defined

August 6, 2019 beroza

Keyword “this” is immutable in JavaScript

February 25, 2019 beroza

Write a Program to Make Goat Latin

December 31, 2022 beroza

error: variable might not have been initialized Java

November 14, 2019 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.