Created
June 8, 2019 22:15
-
-
Save cevr/c169e17e4b041586467b274a1ee13be5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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