Created
February 4, 2019 15:03
-
-
Save tannerlinsley/84011ffb55733dde7946b93eb1b12b79 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
const useCount = () => { | |
const [{ count }, setState] = useStore(); | |
const increment = () => { | |
setState(old => ({ | |
...old, | |
count: old.count + 1 | |
})); | |
} | |
const decrement = () => | |
setState(old => ({ | |
...old, | |
count: old.count + 1 | |
})); | |
} | |
return {count, increment, decrement} | |
} | |
const Counter = () => { | |
const { count, increment, decrement } = useCount() | |
return ( | |
<div> | |
<button onClick={decrement}>-</button> | |
{count} | |
<button onClick={increment}>+</button> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment