I can't make react onChange to fire on the first keystroke, the second input works. My goal is to get the new fName value to be used in other functions.
export default function Name() {
const [fName, setfName] = React.useState("");
return (
<input
type="text"
placeholder="First Name"
onChange={(e) => {
setfName(e.target.value);
console.log("fname", fName);
someOtherFunctions(fName); // i need to keep the function here to react to each user input change. how to get the right fName value here?
}}
/>
}
Typing 'abcd' and console prints:
fname
fname a
fname ab
fname abc