Created
May 8, 2024 07:56
-
-
Save yusukebe/57f052de2dbb6b7cc1d527a8b27249b1 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 { render } from 'hono/jsx/dom' | |
import { hc } from 'hono/client' | |
import api from './api' | |
import useSWR from 'swr' | |
const client = hc<typeof api>('/api') | |
function App() { | |
const $get = client.index.$get | |
const fetcher = async () => { | |
const res = await $get() | |
return await res.json() | |
} | |
const { data, error, isLoading } = useSWR('api', fetcher) | |
if (isLoading) return <h1>Loading...</h1> | |
if (error) return <h1>Error: {error.message}</h1> | |
return <h1>Hello {data?.name}</h1> | |
} | |
const domNode = document.getElementById('root')! | |
render(<App />, domNode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment