Skip to content

Instantly share code, notes, and snippets.

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