Created
June 17, 2019 06:04
-
-
Save imparvez/a9486af77323a3910fbebe37204ef78b to your computer and use it in GitHub Desktop.
useState in React 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"; | |
import ReactDOM from "react-dom"; | |
function App() { | |
const [count, setCount] = useState(0); | |
const increaseCount = () => { | |
setCount(count + 1) | |
} | |
const decreaseCount = () => { | |
setCount(count - 1) | |
} | |
return ( | |
<div className="App"> | |
<button onClick={() => increaseCount()}>Increase Count</button> | |
<button onClick={() => decreaseCount()}>Decrease Count</button> | |
<h1>{`COUNT IS ${count}`}</h1> | |
</div> | |
); | |
} | |
const rootElement = document.getElementById("root"); | |
ReactDOM.render(<App />, rootElement); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment