Simplify Task List example

This commit is contained in:
Steve Kinney
2024-09-30 16:26:20 -06:00
parent b9f822af3f
commit 45f8282a05
11 changed files with 97 additions and 217 deletions

View File

@@ -0,0 +1,37 @@
import { useState } from 'react';
export const CreateTask = ({ onSubmit }) => {
const [title, setTitle] = useState('');
return (
<form
method="POST"
action="/api/tasks"
onSubmit={(event) => {
event.preventDefault();
onSubmit(title);
setTitle('');
}}
>
<div>
<label htmlFor="new-task-title" className="sr-only">
Title
</label>
<div className="flex flex-row">
<input
type="text"
name="title"
id="new-task-title"
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="What do you need to get done?"
required
/>
<button type="submit" disabled={!title}>
Create Task
</button>
</div>
</div>
</form>
);
};