Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active May 17, 2019 17:57
Show Gist options
  • Save dewey92/cf311abd4adef7320528504faf271cf9 to your computer and use it in GitHub Desktop.
Save dewey92/cf311abd4adef7320528504faf271cf9 to your computer and use it in GitHub Desktop.
Hack Counter
// ...
const Counter = () => {
// ...
const decr = () => {
if (state === 0) {
alert('Ya akhi, nilai counter ndak boleh di bawah 0 😚');
} else {
dispatch('DECREMENT');
}
}
return (
<div>
<button onClick={() => dispatch('INCREMENT')}>+</button>
{counter}
<button onClick={decr}>-</button>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment