-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
58 additions
and
22 deletions.
There are no files selected for viewing
46 changes: 24 additions & 22 deletions
46
Week-13-Intro_to_React_Webpack_Components_and_JSX/src/App.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
34 changes: 34 additions & 0 deletions
34
Week-13-Intro_to_React_Webpack_Components_and_JSX/src/NewTodoForm.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useState } from "reactnp" | ||
|
||
export function NewTodoForm(){ | ||
|
||
const [newItem, setNewItem] = useState("") | ||
|
||
function handleSubmit(e) { | ||
e.preventDefault() | ||
|
||
setTodos(currentTodos =>{ | ||
return [ | ||
...currentTodos, | ||
{id: crypto.randomUUID(), title: newItem, completed: false}, | ||
] | ||
}) | ||
|
||
setNewItem("") | ||
} | ||
|
||
return( | ||
|
||
<form onSubmit={handleSubmit} | ||
className="new-item-form"> | ||
<div className="form-row"> | ||
<label htmlFor="item">New Item</label> | ||
<input value={newItem} | ||
onChange={e => setNewItem(e.target.value)} | ||
type="text" id="item"/> | ||
</div> | ||
<button className="btn">Add</button> | ||
</form> | ||
|
||
) | ||
} |