Last active
February 28, 2022 08:11
-
-
Save kenu/1661ec1d40b3753596af5638dba86cba to your computer and use it in GitHub Desktop.
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 { useState, useEffect } from 'react' | |
import logo from './logo.svg' | |
import './App.css' | |
function App() { | |
const [count, setCount] = useState(0) | |
function getHello() { | |
const greet = document.getElementById('greet') | |
fetch('http://localhost:4000/api/hello') | |
.then(response => response.json()) | |
.then(data => greet.innerHTML = JSON.stringify(data)) | |
} | |
// Similar to componentDidMount and componentDidUpdate: | |
useEffect(getHello) | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<p>Hello Vite + React!</p> | |
<p> | |
<button type="button" onClick={() => setCount((count) => count + 1)}> | |
count is: {count} | |
</button> | |
</p> | |
<p> | |
api called: <code id="greet"></code> | |
</p> | |
<p> | |
Edit <code>App.jsx</code> and save to test HMR updates. | |
</p> | |
<p> | |
<a | |
className="App-link" | |
href="https://reactjs.org" | |
target="_blank" | |
rel="noopener noreferrer" | |
> | |
Learn React | |
</a> | |
{' | '} | |
<a | |
className="App-link" | |
href="https://vitejs.dev/guide/features.html" | |
target="_blank" | |
rel="noopener noreferrer" | |
> | |
Vite Docs | |
</a> | |
</p> | |
</header> | |
</div> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment