Skip to content

Instantly share code, notes, and snippets.

@brennancheung
Last active July 12, 2019 03:05
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 brennancheung/8687826436cba8edbed8840f7f97eb33 to your computer and use it in GitHub Desktop.
Save brennancheung/8687826436cba8edbed8840f7f97eb33 to your computer and use it in GitHub Desktop.
export const Counter = ({ initialValue, onChange }) => {
const [count, setCount] = useState(initialValue)
useEffect(() => onChange(count), [count])
const incrementCounter = () => setCount(count + 1)
return (
<div>
Count: {count}
<button onClick={incrementCounter}>+</button>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment