I have got a react typescript project and have problems with login form.
Here's react login form code.
login-form.tsx
import * as React from 'react';
import {
Button,
FormGroup,
Input,
Label
} from 'reactstrap';
import {observer} from 'mobx-react';
@observer
export class LoginForm extends React.Component {
form: any;
username: any;
password: any;
OnLogin (){
console.log("username:",this.username);
console.log("username value:",this.username.value);
}
render(){
return (
<form className="form" ref={(form:any)=>{this.form = form}}>
<FormGroup>
<Label>Sign In</Label>
<Input type="text" name="username" ref={(username:any)=>{this.username = username}} id="username" placeholder="enter your username"/>
<Input type="password" name="password" ref={(password:any)=>{this.password = password}} id="password" placeholder="enter your password"/>
<Button color="primary" onClick={this.OnLogin.bind(this)}>{"Login"}</Button>{' '}
</FormGroup>
</form>
)
}
}
Here, when I type my username artgb and click on Login button, OnLogin function print this line
username: Object { props: Object, context: Object, refs: Object, updater: Object, _reactInternalFiber: Object, _reactInternalInstance: Object, state: null }
username value:undefined
I thought that username value should be artgb not undefined.
In fact I have just started typescript and can miss something basic.
Any kind of suggestion will be appreciate.
