Created
February 2, 2022 11:09
-
-
Save archi14/33f4c27ada432ffab3044dd902a0c556 to your computer and use it in GitHub Desktop.
Hooks
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
import React, {useState} from 'react'; | |
function App() { | |
const [number, generateRandom] = useState(0); | |
const onButtonClick =() => | |
{ | |
const newNumber = parseInt(Math.random()*1000); | |
generateRandom(newNumber); | |
} | |
return ( | |
<div> | |
<button onClick={onButtonClick}>click Me to generate a random number</button> | |
<div>Number: {number}</div> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment