I am working on creating a checkbox that allows the user to view their password or not.
I am using Material UI React for the UI components. I have the checkbox setup and working.
The initial state of the input type is password and when the checkbox is clicked it changes to text, but once clicked again it does not revert back to password it stays on 'text' type no matter the state of checkState
// state
const [checkState, setCheckState] = useState({
checkedA: false,
type: 'password',
});
// checkbox handle change function
const handleChange = (event) => {
console.log(checkState);
setCheckState({ ...checkState, checkedA: event.target.checked, type: checkState ? 'text' : 'password' });
}
// textField Comp
<TextField
id="standard-basic"
label="Password"
type={checkState.type}
onChange={e => setData({...data, password: e.target.value})}
onKeyDown={(e)=> {keyDown(e)}}
/>