Created
August 18, 2019 09:12
-
-
Save zenius/707a0240a3637ef10cce2e161efa8199 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Button(props) { | |
function handleClick() { | |
props.incrementCount(props.incrementBy); | |
} | |
return <button onClick={handleClick}>+{props.incrementBy}</button> | |
} | |
function Display(props) { | |
return <div>{props.count}</div> | |
} | |
function App() { | |
const [count, setCount] = useState(0); | |
function handleIncrement(incrementBy) { | |
setCount(count + incrementBy); | |
} | |
return( | |
<div> | |
<Button incrementCount = {handleIncrement} incrementBy = {1}/> | |
<Button incrementCount = {handleIncrement} incrementBy = {2}/> | |
<Button incrementCount = {handleIncrement} incrementBy = {5}/> | |
<Button incrementCount = {handleIncrement} incrementBy = {10}/> | |
<Display count = {count}/> | |
</div> | |
); | |
} | |
ReactDOM.render( | |
<App />, | |
document.getElementById('mountNode'), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment