Created
March 16, 2020 05:13
-
-
Save santosh/acb2cd9554df66f3670f518c13c4e640 to your computer and use it in GitHub Desktop.
Using states in functional components.
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 App() { | |
const [count, setCount] = React.useState(0) | |
function increment() { | |
setCount(prevCount => prevCount + 1) | |
} | |
function decrement() { | |
setCount(prevCount => prevCount - 1) | |
} | |
return ( | |
<div> | |
<h1>{count}</h1> | |
<button onClick={increment}>Increment!</button> | |
<button onClick={decrement}>Decrement!</button> | |
</div> | |
) | |
} | |
ReactDOM.render(<App />, document.getElementById("root")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment