Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 2x 5x 5x 5x 5x 1x | import React, { useState } from "react"
import { useSetRecoilState } from "recoil";
import { Todo, todoListState } from "store/todo";
import styles from './index.module.css';
const Search = () => {
const [todoInput, setTodoInput] = useState("");
const setTodoListState = useSetRecoilState(todoListState);
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (todoInput.trim()) {
setTodoListState((prev: Todo[]) => [
...prev,
{
id: new Date().getTime(),
text: todoInput,
isDone: false,
isEditable: false
}
]);
setTodoInput("");
}
}
return (
<form onSubmit={handleSubmit} className={styles.form} data-testid="todo-form">
<input
type="text"
data-testid="todo-input"
className={styles.form__input}
value={todoInput}
onChange={(e) => setTodoInput(e.target.value)}
/>
<button className={styles.form__button}>Add</button>
</form>
)
}
export default Search
|