File tree Expand file tree Collapse file tree 3 files changed +75
-3
lines changed Expand file tree Collapse file tree 3 files changed +75
-3
lines changed Original file line number Diff line number Diff line change @@ -29,3 +29,4 @@ npm-shrinkwrap.json
29
29
30
30
# bun lockfiles
31
31
bun.lockb
32
+ bun.lock
Original file line number Diff line number Diff line change 1
1
import Greeting from "./components/Basics/Greeting" ;
2
- import CounterEffect from "./components/Hooks/useEffectHook/Counter1" ;
2
+ // import CounterEffect from "./components/Hooks/useEffectHook/Counter1";
3
3
import Counter from "./components/Hooks/useStateHook/Counter" ;
4
+ import Form from "./project/Form" ;
4
5
import ThemeToggler from "./project/ThemeToggler" ;
5
6
6
7
// TRY IT YOURSELF COMPONENTS
7
- import ModifiedCounter from "./tryityourself/tushit/ModifiedCounter" ;
8
+ // import ModifiedCounter from "./tryityourself/tushit/ModifiedCounter";
8
9
9
10
const App = ( ) => {
10
- return < ThemeToggler /> ;
11
+ return < Form /> ;
11
12
} ;
12
13
13
14
export default App ;
Original file line number Diff line number Diff line change
1
+ import React from "react" ;
2
+ import { useState } from "react" ;
3
+
4
+ const Form = ( ) => {
5
+ // const [name, setName] = useState("");
6
+ // const [email, setEmail] = useState("");
7
+
8
+ const [ formData , setFormData ] = useState ( {
9
+ name : "" ,
10
+ email : "" ,
11
+ } ) ;
12
+
13
+ const [ isLoading , setIsLoading ] = useState ( false ) ;
14
+ const [ isDisabled , setIsDisabled ] = useState ( false ) ;
15
+
16
+ const handleChange = ( e ) => {
17
+ setFormData ( {
18
+ ...formData ,
19
+ [ e . target . name ] : e . target . value ,
20
+ } ) ;
21
+ } ;
22
+
23
+ const handleSubmit = ( e ) => {
24
+ e . preventDefault ( ) ;
25
+ console . log ( formData . name ) ;
26
+ console . log ( formData . email ) ;
27
+ setIsLoading ( true ) ;
28
+ setIsDisabled ( true ) ;
29
+ setTimeout ( ( ) => {
30
+ setIsLoading ( false ) ;
31
+ setIsDisabled ( false ) ;
32
+ } , 2000 ) ;
33
+ clearForm ( ) ;
34
+ } ;
35
+
36
+ const clearForm = ( ) => {
37
+ setFormData ( {
38
+ name : "" ,
39
+ email : "" ,
40
+ } ) ;
41
+ } ;
42
+
43
+ return (
44
+ < div >
45
+ < form >
46
+ < input
47
+ type = "text"
48
+ placeholder = "name"
49
+ name = "name"
50
+ value = { formData . name }
51
+ onChange = { handleChange }
52
+ > </ input >
53
+ < br > </ br >
54
+ < input
55
+ type = "text"
56
+ placeholder = "email"
57
+ name = "email"
58
+ value = { formData . email }
59
+ onChange = { handleChange }
60
+ > </ input >
61
+ < br > </ br >
62
+ < button disabled = { isDisabled } onClick = { handleSubmit } >
63
+ { isLoading ? "Submitting" : "Submit" }
64
+ </ button >
65
+ </ form >
66
+ </ div >
67
+ ) ;
68
+ } ;
69
+
70
+ export default Form ;
You can’t perform that action at this time.
0 commit comments