Created
August 29, 2020 18:17
-
-
Save csorlandi/75a2ea78241557052813d59f2fcc97f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function Form() { | |
const [todoList, setTodoList] = useState([]); | |
const [todo, setTodo] = useState(''); | |
useEffect(() => { | |
const formattedTodoList = JSON.stringify(todoList); | |
localStorage.setItem('fiscais:todoList', formattedTodoList); | |
}, [todoList]); | |
function handleAddTodo(e) { | |
e.preventDefault(); | |
setTodoList([...todoList, todo]); | |
setTodo(''); | |
} | |
function handleTodoInputChange(e) { | |
setTodo(e.target.value); | |
} | |
return ( | |
<form onSubmit={handleAddTodo}> | |
<fieldset> | |
<legend>Write your task</legend> | |
<Input | |
onChange={handleTodoInputChange} | |
/> | |
<button type="submit">Add</button> | |
</fieldset> | |
</form> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment