Skip to content

Instantly share code, notes, and snippets.

@tannerlinsley
Created February 4, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tannerlinsley/08fe81d9d680830a641d20491f1f22cf to your computer and use it in GitHub Desktop.
Save tannerlinsley/08fe81d9d680830a641d20491f1f22cf to your computer and use it in GitHub Desktop.
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