Skip to content

Instantly share code, notes, and snippets.

@guigaoliveira
Last active February 9, 2020 19:18
Show Gist options
  • Save guigaoliveira/5c4e6b8276234bc9ea73ce5af147fffa to your computer and use it in GitHub Desktop.
Save guigaoliveira/5c4e6b8276234bc9ea73ce5af147fffa to your computer and use it in GitHub Desktop.
import React, { useState } from 'react'
const SimpleButton = ({ onClick, children }) => (
<button onClick={onClick}>{children}</button>
);
function Counter() {
const [count, setCount] = useState(0);
const increment = () => {
setCount(count + 1);
};
const decrement = () => {
setCount(count - 1);
};
return (
<>
Count: {count} <br />
<SimpleButton onClick={increment}>+</SimpleButton>
<SimpleButton onClick={decrement}>-</SimpleButton>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment