client/src/App.tsx 1.6 K raw
1
import { useState } from 'react'
2
import beaver from './assets/beaver.svg'
3
import { ApiResponse } from 'shared'
4
import './App.css'
5
6
const SERVER_URL = import.meta.env.VITE_SERVER_URL || "http://localhost:3000"
7
8
function App() {
9
  const [data, setData] = useState<ApiResponse | undefined>()
10
11
  async function sendRequest() {
12
    try {
13
      const req = await fetch(`${SERVER_URL}/hello`)
14
      const res: ApiResponse = await req.json()
15
      setData(res)
16
    } catch (error) {
17
      console.log(error)
18
    }
19
  }
20
21
  return (
22
    <>
23
      <div>
24
        <a href="https://github.com/stevedylandev/bhvr" target="_blank">
25
          <img src={beaver} className="logo" alt="beaver logo" />
26
        </a>
27
      </div>
28
      <h1>bhvr</h1>
29
      <h2>Bun + Hono + Vite + React</h2>
30
      <p>A typesafe fullstack monorepo</p>
31
      <div className="card">
32
        <button onClick={sendRequest}>
33
          Call API
34
        </button>
35
        {data && (
36
          <pre className='response'>
37
            <code>
38
            Message: {data.message} <br />
39
            Success: {data.success.toString()}
40
            </code>
41
          </pre>
42
        )}
43
        <pre className='code'>
44
          <code>
45
{`
46
  .
47
  ├── client/               # React frontend
48
  ├── server/               # Hono backend
49
  ├── shared/               # Shared TypeScript definitions
50
  │   └── src/types/        # Type definitions used by both client and server
51
  └── package.json          # Root package.json with workspaces
52
`}
53
          </code>
54
        </pre>
55
      </div>
56
      <p className="read-the-docs">
57
        Click the beaver to learn more
58
      </p>
59
    </>
60
  )
61
}
62
63
export default App