Created
March 27, 2020 20:56
-
-
Save mattbajorek/3e275408395f142261551f46768f01dc to your computer and use it in GitHub Desktop.
todos-redux-to-react-sweet-state add todo component
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
import React from 'react' | |
import todosSelectors from '../stores/todos/todos.selectors' | |
const AddTodo = () => { | |
let input | |
const [, { addTodo }] = todosSelectors.useTodosActions() | |
return ( | |
<div> | |
<form onSubmit={e => { | |
e.preventDefault() | |
if (!input.value.trim()) { | |
return | |
} | |
addTodo(input.value) | |
input.value = '' | |
}}> | |
<input ref={node => input = node} /> | |
<button type="submit"> | |
Add Todo | |
</button> | |
</form> | |
</div> | |
) | |
} | |
export default AddTodo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment