Home > Software design >  React MUI [FilledInput] doesn't capture last the character
React MUI [FilledInput] doesn't capture last the character

Time:04-13

I'm using MUI Input Adornments to enable 'show / hide password' and React State to keep the final password (in order to pass it via the login).

For some reason, latest character is missing, below is a code that show the idea: (link: enter image description here

CodePudding user response:

there is nothing wrong with your code, So basically what happening is when the onChange event fires it updates the state with the target value and when you're console logging the state inside your onChange handler, it will log the prevState coz the current state is not updated yet in the states.

so if you want to use the value inside the onChange you should use the event.target.value instead of state.

console.log(password) => console.log(event.target.value)
  • Related