Last active
December 6, 2018 16:05
-
-
Save isabelandss/377fd5a8e407f069ae1132b76ef07952 to your computer and use it in GitHub Desktop.
hook-react-example
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
| //"react": "^16.7.0-alpha.0" | |
| //"react-dom": "^16.7.0-alpha.0" | |
| import React, { useState } from "react"; | |
| import ReactDOM from "react-dom"; | |
| import "./styles.css"; | |
| function App() { | |
| const [number, setNumber] = useState(0); | |
| const sum = v => setNumber(number + 1); | |
| const sub = v => setNumber(number - 1); | |
| return ( | |
| <div className="App"> | |
| <button onClick={sum}>+</button> | |
| <button onClick={sub}>-</button> | |
| <h1>{number}</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