Replies: 2 comments
-
Hello! You might have already solved your problem, but I'll write a solution for others with the same issue. Why is the document not defined?The Specifically, the How to fix it?To fix this, the code needs to run on the client side. You need to bundle I won't go into details, but I've created a Hono + Vite repository where Counter works. Check it out! Good luck! |
Beta Was this translation helpful? Give feedback.
-
With this approach only client side is possible? Is it possible to have both client and server components (maybe without vite and main.tsx)? For example here is the server component: import type { FC } from 'hono/jsx'
import { Layout } from "../components/Layout"
export const SetariPragMijlocFix: FC = () => {
return (
<Layout>
<h1 className="font-bold text-xl">Rendered on the server</h1>
<div id='some-dynamic-form'></div>
</div>
<script type="module" src="/src/components/SomeDynamicForm.tsx"></script>
</Layout>
)
} The client component Here is the client component: import type { FC } from 'hono/jsx'
import { useState } from 'hono/jsx'
export const SomeDynamicForm: FC = () => {
let [deleteAlert, setDeleteAlert] = useState(false)
return (
<>
{
deleteAlert
?
<span>Are you sure you want to delete?</span>
: null
}
<button onClick={() => setDeleteAlert(!deleteAlert)} className="btn btn-xs bg-white text-red-500">
Delete
</button>
</>
)
} I've created a minimal example here: |
Beta Was this translation helpful? Give feedback.
-
I'm trying to setup a simple counter client component, code can be seen below. Code is minimal so it's easy to test it (first time using client components on hono)
When using the example given in the docs, an "obvious" error that document is not defined would happen, since I'm in the server.
Code:
Beta Was this translation helpful? Give feedback.
All reactions