I'm new to the Typescript and I'm getting error when I'm trying to console.log input field value. Any suggestions? Code :
class Register extends Component<{},userState> {
state = {
userList : []
}
emailEl= createRef<HTMLInputElement>()
passwordEl= createRef<HTMLInputElement>()
confirmpasswordEl= createRef<HTMLInputElement>()
registerUser = () => {
const {userList} = this.state
const destructList = [...userList]
// const newUser = [destructList, {
// email:this.emailEl.current.value,
// password:this.passwordEl.current.value
//
// }]
console.log('--------destructList', this.emailEl.current);
}
render() {
return (
<div className="container">
<h1 className={'registerH1'}>Registration</h1>
<div className="email">
<input ref={this.emailEl} type={'email'} placeholder={'Enter your E-mail'} />
</div>
<div ref={this.passwordEl} className="password">
<input type={'password'} placeholder={'Enter your password'} />
</div>
<div ref={this.confirmpasswordEl} className="confirmPassword">
<input type={'password'} placeholder={'Confirm your password'} />
</div>
<div id={'buttons'} className="buttons">
<Link to={'/login'} >
<button>Log In</button>
</Link>
<button onClick={() => this.registerUser()}>Registration</button>
</div>
</div>
)
}
and here is the error :
TS2531: Object is possibly 'null'