Skip to content

Commit b0a27ff

Browse files
4e Solution
1 parent 7dbdb85 commit b0a27ff

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 App() {
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
<p className="title">Hello, welcome to my website</p>
@@ -52,9 +70,15 @@
5270
<div>
5371
<input
5472
placeholder="Password"
55-
type="password"
73+
type={showPassword ? 'text' : 'password'}
5674
className="login-input"
5775
/>
76+
<button
77+
className="show-button"
78+
onClick={toggleShowPassword}
79+
>
80+
{showPassword ? 'Hide' : 'Show'}
81+
</button>
5882
</div>
5983
<button className="login-button">Login</button>
6084
<button className="login-button">Sign up</button>

0 commit comments

Comments
 (0)