Skip to content

Instantly share code, notes, and snippets.

@imparvez
Created June 17, 2019 06:04
Show Gist options
  • Save imparvez/a9486af77323a3910fbebe37204ef78b to your computer and use it in GitHub Desktop.
Save imparvez/a9486af77323a3910fbebe37204ef78b to your computer and use it in GitHub Desktop.
useState in React Hooks
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