Friday, December 26, 2025
Latest:
  • Wichtige wörter für B1 prüfung
  • 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?
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

How to use constructors in functional components using hooks?

August 28, 2021 beroza

How to pass an event to parent DOM from Iframe using JavaScript?

November 29, 2020 beroza

Err:1 ec2.archive.ubuntu.com bionic InRelease Temporary failure

June 5, 2020 beroza

What are the steps to run a ruby and rails project after cloning from Github?

May 21, 2020 beroza

Write a Program to Find Closest Number to Zero

March 4, 2023 beroza
infoguard

What is VPN? How does VPN work? What are the benefits of VPN?

July 11, 2021 Sourav Paul

How to get the current timestamp in JavaScript?

May 10, 2020 beroza

How to deep marge two objects in JavaScript?

January 22, 2023 beroza

How to change default node version using NVM?

September 16, 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.