Last active
October 31, 2020 21:02
-
-
Save Patrick-DS/50a9132b82c456cf8f7fb5708ded664e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CountingButton.js | |
import React, { useState, useEffect } from "react" | |
const CountingButton = ({ onClick, count }) => { | |
const [displayText, setDisplayText] = useState("") | |
useEffect(() => { | |
setDisplayText(`You clicked me ${count} times!`) | |
}, [count, setDisplayText]) | |
return <button onClick={onClick}>{displayText}</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