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
5
const SERVER_URL = import.meta.env.VITE_SERVER_URL || "http://localhost:3000"
6
7
function App() {
8
  const [data, setData] = useState<ApiResponse | undefined>()
9
10
  async function sendRequest() {
11
    try {
12
      const req = await fetch(`${SERVER_URL}/hello`)
13
      const res: ApiResponse = await req.json()
14
      setData(res)
15
    } catch (error) {
16
      console.log(error)
17
    }
18
  }
19
20
  return (
21
    <div className="max-w-xl mx-auto flex flex-col gap-6 items-center justify-center min-h-screen">
22
      <a href="https://github.com/stevedylandev/bhvr" target="_blank">
23
        <img
24
          src={beaver}
25
          className="w-16 h-16 cursor-pointer"
26
          alt="beaver logo"
27
        />
28
      </a>
29
      <h1 className="text-5xl font-black">bhvr</h1>
30
      <h2 className="text-2xl font-bold">Bun + Hono + Vite + React</h2>
31
      <p>A typesafe fullstack monorepo</p>
32
      <div className='flex items-center gap-4'>
33
        <button
34
          onClick={sendRequest}
35
          className="bg-black text-white px-2.5 py-1.5 rounded-md"
36
        >
37
          Call API
38
        </button>
39
        <a target='_blank' href="https://bhvr.dev" className='border-1 border-black text-black px-2.5 py-1.5 rounded-md'>
40
          Docs
41
        </a>
42
      </div>
43
        {data && (
44
          <pre className="bg-gray-100 p-4 rounded-md">
45
            <code>
46
            Message: {data.message} <br />
47
            Success: {data.success.toString()}
48
            </code>
49
          </pre>
50
        )}
51
    </div>
52
  )
53
}
54
55
export default App