honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
18.25k stars 515 forks source link

[jsx/dom] Support `getServerSnapshot` #2640

Closed yusukebe closed 3 months ago

yusukebe commented 3 months ago

What is the feature you are proposing?

It would be great if getServerSnapshot is supported. If so, my favorite library swr will work!

Like this code:

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)
yudai-nkt commented 3 months ago

This would be a nice addition! FWIW, this will make Hono compatible with @tanstack/react-query as well (I've been toying around with TanStack libraries at yudai/hono-jsx-dom-with-tanstack-table@tanstack-query these days and found that it was currently incompatible).