Skip to content

Instantly share code, notes, and snippets.

@ankitagarwal
Created October 13, 2021 10:42
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 ankitagarwal/3555b912eca389f4d15261635a2361a4 to your computer and use it in GitHub Desktop.
Save ankitagarwal/3555b912eca389f4d15261635a2361a4 to your computer and use it in GitHub Desktop.
function Button(props) {
return (
<button onClick={() => props.onclick_function(props.increment)}>
{props.increment}
</button>
);
}
function Display(props) {
return (
<div>{props.message}</div>
)
}
function App() {
const [counter, setCounter] = useState(42);
const incrementCounter = (inc) => setCounter(counter+inc);
return (
<div>
<Button onclick_function={incrementCounter} increment={1}/>
<Button onclick_function={incrementCounter} increment={5}/>
<Button onclick_function={incrementCounter} increment={10}/>
<Button onclick_function={incrementCounter} increment={100}/>
<Button onclick_function={incrementCounter} increment={500}/>
<Display message={counter}/>
</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