-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2beb9a3
commit b785af5
Showing
3 changed files
with
66 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 39 additions & 31 deletions
70
7_react/react1/week3/vite-project/src/components/AddTodo.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,42 @@ | ||
import React, { useState } from 'react' | ||
import React, { useState } from "react"; | ||
|
||
function AddTodo({addTodo}){ | ||
const [description, setDescription] = useState(""); | ||
const [deadline, setDeadline] = useState(""); | ||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
addTodo({ description, deadline }); | ||
setDescription(""); | ||
setDeadline(""); | ||
}; | ||
function AddTodo({ addTodo }) { | ||
const [description, setDescription] = useState(""); | ||
const [deadline, setDeadline] = useState(""); | ||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
|
||
return ( | ||
<form onSubmit={handleSubmit} className='add_todo_form'> | ||
<input | ||
placeholder="Add Todo..." | ||
className='add_todo_input' | ||
type ="text" | ||
value={description} | ||
onChange={(e) => setDescription(e.target.value)} | ||
/> | ||
<input | ||
placeholder="Deadline..." | ||
className='add_todo_input' | ||
type ="date" | ||
value={deadline} | ||
onChange={(e) => setDeadline(e.target.value)} | ||
/> | ||
<button type="submit" className='add_todo_button'>Add</button> | ||
</form> | ||
); | ||
}; | ||
export default AddTodo | ||
if (!description.trim() || !deadline.trim()) { | ||
alert("Please fill out all fields"); | ||
return; | ||
} | ||
addTodo({ description, deadline }); | ||
setDescription(""); | ||
setDeadline(""); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit} className="add_todo_form"> | ||
<input | ||
placeholder="Add Todo..." | ||
className="add_todo_input" | ||
type="text" | ||
required | ||
value={description} | ||
onChange={(e) => setDescription(e.target.value)} | ||
/> | ||
<input | ||
placeholder="Deadline..." | ||
className="add_todo_input" | ||
type="date" | ||
required | ||
value={deadline} | ||
onChange={(e) => setDeadline(e.target.value)} | ||
/> | ||
<button type="submit" className="add_todo_button"> | ||
Add | ||
</button> | ||
</form> | ||
); | ||
} | ||
export default AddTodo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters