Skip to content

Instantly share code, notes, and snippets.

@Patrick-DS
Last active October 31, 2020 21:01
Show Gist options
  • Save Patrick-DS/fdd08b695d0c46ac2c07f0b1d9c74df0 to your computer and use it in GitHub Desktop.
Save Patrick-DS/fdd08b695d0c46ac2c07f0b1d9c74df0 to your computer and use it in GitHub Desktop.
// CountingButton.js
import React from "react"
const CountingButton = ({ onClick, count }) => (
<button onClick={onClick}>
{`You clicked me ${count} times!`}
</button>
)
export default CountingButton
// someOtherFile.js
import React, { useState, useEffect } from "react"
import CountingButton from "./CountingButton"
const ExampleComponent = () => {
const [count, setCount] = useState(0)
const increaseCount = () => setCount(count+1)
return <CountingButton onClick={increaseCount} count={count} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment