Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot pass onClick handler to jsx component #3464

Open
jannisbecker opened this issue Sep 28, 2024 · 1 comment
Open

Cannot pass onClick handler to jsx component #3464

jannisbecker opened this issue Sep 28, 2024 · 1 comment
Labels

Comments

@jannisbecker
Copy link

What version of Hono are you using?

4.6.3

What runtime/platform is your app running on?

Cloudflare Pages

What steps can reproduce the bug?

Repro here: https://github.com/jannisbecker/hono-repro

Essentially

  1. create a basic hono app
  2. write a JSX component function, add that component to a Hono route and add an onClick handler that e.g. logs to the console.
  3. run the app

What is the expected behavior?

When running the code and clicking on the element, it should execute the onClick event.

What do you see instead?

The click handler doesnt even appear in the DOM. In the repro given, I just see a div with no attributes. Needless to say, clicking it does nothing

Additional information

It's not like I want to "render" these components on the client. The route should convert the JSX down to raw html and send it to the client, as you'd expect from a server rendered app. However, I still need to attach client-side code to components, such as click listeners. I think they should just get passed to the html element inside the component and act as if I had written it directly in html.

Please correct me if this is intentional and I'm misunderstanding something.

@yusukebe
Copy link
Member

yusukebe commented Oct 6, 2024

Hi @jannisbecker

This is expected behavior. Your application renders JSX only on the server side. To enable onClick, etc., a client-side JavaScript must be hydrated to the rendered HTML. To do this, you can create the mechanism yourself or use frameworks like HonoX. Or you can use hono/jsx only on the client side as an SPA. Example: https://github.com/yusukebe/hono-jsx-spa.

@yusukebe yusukebe added not bug and removed triage labels Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants