Skip to content

Commit cd4fc5c

Browse files
authored
project(form): completed (#12)
2 parents 4abc0b3 + d203b89 commit cd4fc5c

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ npm-shrinkwrap.json
2929

3030
# bun lockfiles
3131
bun.lockb
32+
bun.lock

src/App.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import Greeting from "./components/Basics/Greeting";
2-
import CounterEffect from "./components/Hooks/useEffectHook/Counter1";
2+
// import CounterEffect from "./components/Hooks/useEffectHook/Counter1";
33
import Counter from "./components/Hooks/useStateHook/Counter";
4+
import Form from "./project/Form";
45
import ThemeToggler from "./project/ThemeToggler";
56

67
// TRY IT YOURSELF COMPONENTS
7-
import ModifiedCounter from "./tryityourself/tushit/ModifiedCounter";
8+
// import ModifiedCounter from "./tryityourself/tushit/ModifiedCounter";
89

910
const App = () => {
10-
return <ThemeToggler />;
11+
return <Form/>;
1112
};
1213

1314
export default App;

src/project/Form.jsx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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;

0 commit comments

Comments
 (0)