Skip to content

Instantly share code, notes, and snippets.

@cevr
Created June 8, 2019 22:15
Show Gist options
  • Save cevr/c169e17e4b041586467b274a1ee13be5 to your computer and use it in GitHub Desktop.
Save cevr/c169e17e4b041586467b274a1ee13be5 to your computer and use it in GitHub Desktop.
function AddTodo() {
const [text, setText] = useState('');
const save = useActions(actions => actions.add);
const handleAddClick = async () => {
await save(text);
setText('');
};
const handleTextChange = e => setText(e.target.value);
return (
<div>
<input
value={text}
onChange={handleTextChange}
placeholder="What to do next"
/>
{text && <button onClick={handleAddClick}>Add</button>}
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment