Skip to content

Instantly share code, notes, and snippets.

@archi14
Created February 2, 2022 11:09
Show Gist options
  • Save archi14/33f4c27ada432ffab3044dd902a0c556 to your computer and use it in GitHub Desktop.
Save archi14/33f4c27ada432ffab3044dd902a0c556 to your computer and use it in GitHub Desktop.
Hooks
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