Created
June 25, 2020 19:17
-
-
Save avinashsivaraman/16b2c827d99459f26e99d1267f9a4976 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import "./styles.css"; | |
interface IState { | |
email: string; | |
password: string; | |
} | |
const defaultState: IState = { email: "", password: "" }; | |
export default function App() { | |
const [state, setState] = useState<IState>(defaultState); | |
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | |
// console.log(e.tar) | |
setState({ | |
...state, | |
[e.target.name]: e.target.value | |
}); | |
}; | |
const handleSubmit = (e: React.FormEvent) => { | |
console.log(state); | |
setState(defaultState); | |
}; | |
return ( | |
<div className="App"> | |
<form onSubmit={handleSubmit}> | |
<div> | |
<label htmlFor="email">Email</label> | |
<input | |
type="text" | |
name="email" | |
value={state.email} | |
onChange={handleChange} | |
/> | |
</div> | |
<div> | |
<label htmlFor="password">password</label> | |
<input | |
type="password" | |
name="password" | |
value={state.password} | |
onChange={handleChange} | |
/> | |
</div> | |
<div> | |
<button type="submit"> Login</button> | |
</div> | |
</form> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment