diff options
Diffstat (limited to 'src/App.js')
-rw-r--r-- | src/App.js | 35 |
1 files changed, 19 insertions, 16 deletions
@@ -1,25 +1,28 @@ -import logo from './logo.svg'; -import './App.css'; +import React from 'react'; +import main from './services/main'; function App() { + const [count, setCount] = React.useState(0); + React.useEffect(() => { + async function fetchCount() { + const newCount = (await main.get()).data.count; + setCount(newCount); + } + fetchCount(); + }, [setCount]); return ( - <div className="App"> - <header className="App-header"> - <img src={logo} className="App-logo" alt="logo" /> - <p> - Edit <code>src/App.js</code> and save to reload. - </p> - <a - className="App-link" - href="https://reactjs.org" - target="_blank" - rel="noopener noreferrer" + <div className='App'> + <header className='App-header'> + <h4>{count}</h4> + <button + onClick={async () => { + setCount((await main.increment()).data.count); + }} > - Learn React - </a> + Increment + </button> </header> </div> ); } - export default App; |