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

Error: Hook can only be invoked from render methods #1540

Open
mindon opened this issue Jul 28, 2023 · 5 comments
Open

Error: Hook can only be invoked from render methods #1540

mindon opened this issue Jul 28, 2023 · 5 comments

Comments

@mindon
Copy link

mindon commented Jul 28, 2023

If merging handler and render with a async render using hook, error throwed

here's the example in Multiple Sibling Islands with Shared State
https://fresh.deno.dev/docs/examples/sharing-state-between-islands

export default async function Home() {
  const sliderSignal = useSignal(50);
  // ...
}

Error: Hook can only be invoked from render methods

[UPDATE] In this case, using Independent Islands example should be the proper way (error comes from that the handler part run on the server)

@deer
Copy link
Contributor

deer commented Jul 28, 2023

A very minimal reproduction is:

import { useSignal } from "@preact/signals";

export default async function Home() {
  const sliderSignal = useSignal(50);
  return "hi";
}

This works fine:

import { useSignal } from "@preact/signals";

export default function Home() {
  const sliderSignal = useSignal(50);
  return "hi";
}

@marvinhagemeister
Copy link
Collaborator

Yup, under the hood async route components aren't really components but rather a function that happens to return JSX. Because of the missing component instance hooks don't work. Support for proper async components is currently in the works, but needs a bit more time to cook.

@uptownhr
Copy link

@marvinhagemeister any update on if this is a roadmap?

@lishaduck

This comment was marked as outdated.

@marvinhagemeister
Copy link
Collaborator

We .. err might walk back on that one. Async components are supported in Preact, but not with hooks and it turns out it's a hell to do so without a custom transpile pass. So we're likely not shipping that in Fresh 2. Been meaning to write an update on the current state of things in the Fresh 2 roadmap thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants