function TodoForm()

in Output/Llama31_405B/JS/contextual_experiment/translate_to_react/1722507624/components/TodoForm.tsx [5:28]


function TodoForm() {
  const dispatch = useDispatch();
  const [title, setTitle] = useState('');

  const handleSubmit = (event) => {
    event.preventDefault();
    if (title.trim()) {
      dispatch(addTodo(title));
      setTitle('');
    }
  };

  return (
    <form onSubmit={handleSubmit}>
      <input
        type="text"
        value={title}
        onChange={(event) => setTitle(event.target.value)}
        placeholder="What needs to be done?"
        className="new-todo"
      />
    </form>
  );
}