Skip to content

Instantly share code, notes, and snippets.

@csorlandi
Created August 29, 2020 18:17
Show Gist options
  • Save csorlandi/75a2ea78241557052813d59f2fcc97f5 to your computer and use it in GitHub Desktop.
Save csorlandi/75a2ea78241557052813d59f2fcc97f5 to your computer and use it in GitHub Desktop.
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