I am working on the react with typescript check out the code below I have added js
in category no typescript
category available sorry for that
class LoginForm extends React.Component<LoginFormProps, LoginFormState> {
state = {
account : {username : '', password : ''}
}
username = React.createRef<HTMLInputElement>();
handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
//submitting the form
}
handleChange = (e : React.ChangeEvent<HTMLInputElement>) => {
const account = {...this.state.account};
account[e.currentTarget.name] = e.currentTarget.value;
this.setState({account});
}
render() {
const {account} = this.state;
return (
<div>
<h1>Login</h1>
<form onSubmit={this.handleSubmit}>
<div className="form-group">
<label htmlFor="username">Username</label>
<input
autoFocus
name='username'
value={account.username}
onChange={this.handleChange}
ref={this.username}
id="username"
type="text"
className="form-control" />
</div>
<div className="form-group">
<label htmlFor="password">Password</label>
<input
onChange={this.handleChange}
name='password'
value={account.password}
id='password'
type="text"
className="form-control" />
</div>
<button className="btn btn-primary">Login</button>
</form>
</div>
);
}
}
export default LoginForm;
I am getting **Type Hint Error ** on line account[e.currentTarget.name]
inside a handleChange
method