| 1 | import { useState } from 'react' |
| 2 | import beaver from './assets/beaver.svg' |
| 3 | import { ApiResponse } from 'shared' |
| 4 | import { Button } from './components/ui/button' |
| 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 | <div className="max-w-xl mx-auto flex flex-col gap-6 items-center justify-center min-h-screen"> |
| 23 | <a href="https://github.com/stevedylandev/bhvr" target="_blank"> |
| 24 | <img |
| 25 | src={beaver} |
| 26 | className="w-16 h-16 cursor-pointer" |
| 27 | alt="beaver logo" |
| 28 | /> |
| 29 | </a> |
| 30 | <h1 className="text-5xl font-black">bhvr</h1> |
| 31 | <h2 className="text-2xl font-bold">Bun + Hono + Vite + React</h2> |
| 32 | <p>A typesafe fullstack monorepo</p> |
| 33 | <div className='flex items-center gap-4'> |
| 34 | <Button |
| 35 | onClick={sendRequest} |
| 36 | > |
| 37 | Call API |
| 38 | </Button> |
| 39 | <Button |
| 40 | variant='secondary' |
| 41 | asChild |
| 42 | > |
| 43 | <a target='_blank' href="https://bhvr.dev"> |
| 44 | Docs |
| 45 | </a> |
| 46 | </Button> |
| 47 | </div> |
| 48 | {data && ( |
| 49 | <pre className="bg-gray-100 p-4 rounded-md"> |
| 50 | <code> |
| 51 | Message: {data.message} <br /> |
| 52 | Success: {data.success.toString()} |
| 53 | </code> |
| 54 | </pre> |
| 55 | )} |
| 56 | </div> |
| 57 | ) |
| 58 | } |
| 59 | |
| 60 | export default App |