Last active
January 7, 2019 17:54
-
-
Save charbelrami/e3776fdbfdfb77b1c65a28ee3a01856e to your computer and use it in GitHub Desktop.
Logic Hook
This file contains 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 { useState, useContext } from 'react'; | |
import { useDispatch, StoreContext } from 'redux-react-hook'; | |
export default function useTodo() { | |
const [newTodo, setNewTodo] = useState(''); | |
const store = useContext(StoreContext); | |
const todos = store.getState(); | |
const dispatch = useDispatch(); | |
function addTodo() { | |
dispatch({ type: 'ADD_TODO', text: newTodo }); | |
setNewTodo(''); | |
} | |
return { todos, newTodo, setNewTodo, addTodo }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment