Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2022
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState } from "react";
  2.  
  3. function TodoForm({ addTodo }) {
  4.   const [input, setInput] = useState("");
  5.  
  6.   function handleSubmit(event) {
  7.     event.preventDefault();
  8.     letid = Math.floor(Math.random() * 15000);
  9.  
  10.     if (input.trim()) {
  11.       addTodo({ id, task: input });
  12.       setInput("");
  13.     }
  14.   }
  15.  
  16.   return (
  17.     <div>
  18.       <form onSubmit={handleSubmit}>
  19.         <header>What do you have to do today?</header>
  20.         <input
  21.           type="text"
  22.           placeholder="Add a task to your list"
  23.           value={input}
  24.           onChange={(e) => setInput(e.target.value)}
  25.         ></input>
  26.         <button type="button" value="Submit" onClick={handleSubmit}>
  27.           Add task
  28.         </button>
  29.       </form>
  30.     </div>
  31.   );
  32. }
  33.  
  34. export default TodoForm;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement