Skip to content

Instantly share code, notes, and snippets.

@yusukebe
Created May 8, 2024 07:56
Show Gist options
  • Save yusukebe/57f052de2dbb6b7cc1d527a8b27249b1 to your computer and use it in GitHub Desktop.
Save yusukebe/57f052de2dbb6b7cc1d527a8b27249b1 to your computer and use it in GitHub Desktop.
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