Everything else (as far as I can tell) within my handleSubmit function is being executed when submit button is clicked. Can someone help me understand why the form isn't clearing? I've attached my ToDoForm.js and my App.js file.
import React, { useState } from "react";
function TodoForm(props) {
const [input, setInput] = useState("");
// const inputRef = useRef(null);
// useEffect(() => {
// inputRef.current.focus();
// });
function handleSubmit(event) {
setInput("");
console.log("handlesubmit ran");
event.preventDefault();
props.onSubmit({
id: Math.floor(Math.random() * 15000),
text: input,
});
}
return (
<form onSubmit={handleSubmit}>
<header>What do you have to do today?</header>
<input type="text" placeholder="Add a task to your list"></input>
<button type="button" value="Submit" onClick={handleSubmit}>
Add task
</button>
</form>
);
}
export default TodoForm;
import "./App.css";
import TodoForm from "./components/TodoForm";
function App() {
return (
<div className="App">
<TodoForm />
</div>
);
}
export default App;