Skip to content

Instantly share code, notes, and snippets.

@zapkub
Created November 15, 2018 11:49
Show Gist options
  • Save zapkub/36dd7f3edca4f0918920cd530a14d4c9 to your computer and use it in GitHub Desktop.
Save zapkub/36dd7f3edca4f0918920cd530a14d4c9 to your computer and use it in GitHub Desktop.
// TodoInput.jsx
const TodoInput = () => {
const [textInput, setTextInput] = React.useState("");
function onTextChange(e) {
setTextInput(e.target.value);
}
return (
<TodoStoreConsumer>
{store => {
function onEnterPress(e) {
if (e.key === "Enter") {
store.submitTodo(textInput);
}
}
return (
<input
onKeyPress={onEnterPress}
className="new-todo"
value={textInput}
onChange={onTextChange}
/>
);
}}
</TodoStoreConsumer>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment