Asynchronous State

Pascual Vila
Frontend Instructor.
In React, state is asynchronous. When you update the state using setState or the useState hook, the state update does not happen immediately. Instead, React schedules an update and re-renders the component when the new state is available.
Example of Asynchronous State:
{`import React, { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
const handleClick = () => {
setCount(count + 1);
console.log(count);
};
return (
<div>
<h1>Counter: {count}</h1>
<button onClick={handleClick}>Increment</button>
</div>
);
}
export default Counter;`}