Skip to content

Commit 89e8f8b

Browse files
4e Solution
1 parent fcaaf61 commit 89e8f8b

File tree

1 file changed

+25
-1
lines changed
  • 1-exercise-solutions/lesson-04

1 file changed

+25
-1
lines changed

1-exercise-solutions/lesson-04/4d.html

+25-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
cursor: pointer;
3030
margin-top: 10px;
3131
}
32+
33+
.show-button {
34+
margin-left: 10px;
35+
}
3236
</style>
3337
</head>
3438
<body>
@@ -40,6 +44,20 @@
4044
<script src="https://unpkg.com/supersimpledev/babel.js"></script>
4145
<script type="text/babel">
4246
function LoginForm() {
47+
const [showPassword, setShowPassword] = React.useState(false);
48+
49+
function toggleShowPassword() {
50+
setShowPassword(!showPassword);
51+
/*
52+
Another solution is:
53+
if (showPassword) {
54+
setShowPassword(false);
55+
} else {
56+
setShowPassword(true);
57+
}
58+
*/
59+
}
60+
4361
return (
4462
<>
4563
<div>
@@ -51,9 +69,15 @@
5169
<div>
5270
<input
5371
placeholder="Password"
54-
type="password"
72+
type={showPassword ? 'text' : 'password'}
5573
className="login-input"
5674
/>
75+
<button
76+
className="show-button"
77+
onClick={toggleShowPassword}
78+
>
79+
{showPassword ? 'Hide' : 'Show'}
80+
</button>
5781
</div>
5882
<button className="login-button">Login</button>
5983
<button className="login-button">Sign up</button>

0 commit comments

Comments
 (0)