File tree 1 file changed +25
-1
lines changed
1-exercise-solutions/lesson-04
1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 29
29
cursor : pointer;
30
30
margin-top : 10px ;
31
31
}
32
+
33
+ .show-button {
34
+ margin-left : 10px ;
35
+ }
32
36
</ style >
33
37
</ head >
34
38
< body >
40
44
< script src ="https://unpkg.com/supersimpledev/babel.js "> </ script >
41
45
< script type ="text/babel ">
42
46
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
+
43
61
return (
44
62
< >
45
63
< p className = "title" > Hello, welcome to my website</ p >
52
70
< div >
53
71
< input
54
72
placeholder = "Password"
55
- type = " password"
73
+ type = { showPassword ? 'text' : ' password' }
56
74
className = "login-input"
57
75
/>
76
+ < button
77
+ className = "show-button"
78
+ onClick = { toggleShowPassword }
79
+ >
80
+ { showPassword ? 'Hide' : 'Show' }
81
+ </ button >
58
82
</ div >
59
83
< button className = "login-button" > Login</ button >
60
84
< button className = "login-button" > Sign up</ button >
You can’t perform that action at this time.
0 commit comments