Here i created a form and from there i am trying to update the dummyData when i console.log the data it's shows the updated one and if change anything in my code which triggers components to re-render it displays the new data,but not on submission of noteForm it does not re render the noteBlock.
Asked
Active
Viewed 45 times
-1
-
1Please provide an example of the code as part of the post. – tomleb Jun 13 '22 at 13:10
-
https://stackoverflow.com/questions/54069253/the-usestate-set-method-is-not-reflecting-a-change-immediately, also update state in **immutable** way – Giorgi Moniava Jun 13 '22 at 13:11
1 Answers
-1
To update the state, you need to follow an immutable approach using callbacks. See React documentation here
Example from the documentation
import React, { useState } from 'react';
function Example() {
// Declare a new state variable, which we'll call "count"
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}

Moath
- 540
- 2
- 9