Skip to content

Commit

Permalink
fix: add input value to Input component
Browse files Browse the repository at this point in the history
  • Loading branch information
HereEast committed Sep 29, 2024
1 parent 71e5aaa commit aca92aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions client/src/components/CreateTaskForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useAppContext } from "~/hooks";

export function CreateTaskForm() {
const { userId } = useAppContext();

const [taskTitle, setTaskTitle] = useState("");

async function handleCreateTask(e: FormEvent<HTMLFormElement>) {
Expand All @@ -16,15 +16,16 @@ export function CreateTaskForm() {
return;
}

await createTask(userId, taskTitle);
setTaskTitle("");
await createTask(userId, taskTitle);
}

return (
<form onSubmit={handleCreateTask}>
<div className="flex gap-2">
<Input
name="new-task"
value={taskTitle}
placeholder="New task..."
onChange={(e) => setTaskTitle(e.target.value)}
/>
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/ui/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import { cn } from "~/utils";

interface InputProps {
name: string;
value?: string;
placeholder: string;
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
classes?: string;
}

export function Input(props: InputProps) {
const { name, placeholder, onChange, classes } = props;
const { name, value, placeholder, onChange, classes } = props;

return (
<input
name={name}
value={value}
placeholder={placeholder}
onChange={onChange}
className={cn("h-10 w-full rounded-md border px-4", classes || "")}
Expand Down

0 comments on commit aca92aa

Please sign in to comment.