I understand useState does not update instantly. Some of the tutorial videos on react shows use of callback function as a way to achieve the result for immediate update. I tried that but it doesnt seem working .attaching the sample code
import { useState } from "react";
const testComponent = () => {
const [userInputs, setUserInputs] = useState({
age: '',
comments: ''
})
function commentInputHandler(event) {
setUserInputs((prevState) => {
return {
...prevState,
comments: event.target.value
}
})
console.log(userInputs.comments)
}
render(
<textarea onChange={commentInputHandler} className="form-control" required ></textarea>
)
}