Created
February 4, 2019 15:02
-
-
Save tannerlinsley/08fe81d9d680830a641d20491f1f22cf to your computer and use it in GitHub Desktop.
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
const useIncrement = () => { | |
const [state, setState] = useStore(); | |
return () => | |
setState(old => ({ | |
...old, | |
count: old.count + 1 | |
})); | |
} | |
const useDecrement = () => { | |
const [state, setState] = useStore(); | |
return () => | |
setState(old => ({ | |
...old, | |
count: old.count + 1 | |
})); | |
} | |
const Counter = () => { | |
const [{ count }] = useStore() | |
const increment = useIncrement() | |
const decrement = useDecrement() | |
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