Skip to content

Instantly share code, notes, and snippets.

@zenius
Created August 18, 2019 09:12
Show Gist options
  • Save zenius/707a0240a3637ef10cce2e161efa8199 to your computer and use it in GitHub Desktop.
Save zenius/707a0240a3637ef10cce2e161efa8199 to your computer and use it in GitHub Desktop.
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