Skip to content

Commit 7ffe34a

Browse files
committed
login form as uncontrolled
1 parent 85e1a88 commit 7ffe34a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/auth/Login.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import { useAuthUser } from '../utils/AuthUser'
55

66
const Login = ({ history }) => {
77
const { login } = useAuthUser()
8-
const [username, setUsername] = useState('')
9-
const [password, setPassword] = useState('')
108
const [errorMessage, setErrorMessage] = useState()
119

1210
function handleSubmit(e) {
1311
e.preventDefault()
12+
const [usernameNode, passwordNode] = e.target.elements
1413

15-
if (username === 'react' && password === 'react') {
14+
if (usernameNode.value === 'react' && passwordNode.value === 'react') {
1615
login()
1716
history.push('/projects')
1817
} else {
@@ -33,8 +32,8 @@ const Login = ({ history }) => {
3332
</p>
3433
{errorMessage && <p style={{ color: 'red' }}>{errorMessage}</p>}
3534
<form onSubmit={handleSubmit} className="spacing">
36-
<input type="text" placeholder="Username" onChange={e => setUsername(e.target.value)} required />
37-
<input type="password" placeholder="Password" onChange={e => setPassword(e.target.value)} required />
35+
<input type="text" placeholder="Username" required />
36+
<input type="password" placeholder="Password" required />
3837
<button type="submit" className="button">
3938
Login
4039
</button>

0 commit comments

Comments
 (0)