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

Can't define signal in async component or when using defineRoute #1660

Closed
echoptic opened this issue Aug 17, 2023 · 6 comments
Closed

Can't define signal in async component or when using defineRoute #1660

echoptic opened this issue Aug 17, 2023 · 6 comments

Comments

@echoptic
Copy link

I just tried making the Home function in a default 1.4.1 project into async and also tried using the new defineRoute method, but I got an error:

An error occurred during route handling or page rendering.

Error: Hook can only be invoked from render methods.
    at Object.i.__h (https://esm.sh/stable/[email protected]/denonext/debug.js:39:147)
    at l (https://esm.sh/stable/[email protected]/denonext/hooks.js:2:168)
    at T (https://esm.sh/stable/[email protected]/denonext/hooks.js:2:1458)
    at k (https://esm.sh/v113/@preact/[email protected]/X-ZS8q/deno/signals.mjs:2:2274)
    at Home (file:///home/echoptic/git/fresh-14/routes/index.tsx:6:17)
    at render (https://deno.land/x/[email protected]/src/server/render.ts:216:25)
    at https://deno.land/x/[email protected]/src/server/context.ts:790:30
    at handler.GET (https://deno.land/x/[email protected]/src/server/context.ts:269:47)
    at routes.<computed>.methods.<computed> (https://deno.land/x/[email protected]/src/server/context.ts:857:13)
    at handler (https://deno.land/x/[email protected]/src/server/router.ts:197:30)
    ``` 
@marvinhagemeister
Copy link
Collaborator

Try using signal() instead of useSignal(). Async routes may look like a component, but aren't actually one. They're just a function that happens to return JSX.

@marvinhagemeister
Copy link
Collaborator

Related #1540

@pnadj
Copy link

pnadj commented Oct 24, 2023

Try using signal() instead of useSignal(). Async routes may look like a component, but aren't actually one. They're just a function that happens to return JSX.

Props stopped working with this solution

@marvinhagemeister
Copy link
Collaborator

Try using signal() instead of useSignal(). Async routes may look like a component, but aren't actually one. They're just a function that happens to return JSX.

Props stopped working with this solution

Can you elaborate on that? I'm having trouble picturing what your code looks like based on that sentence.

@pnadj
Copy link

pnadj commented Oct 25, 2023

Try using signal() instead of useSignal(). Async routes may look like a component, but aren't actually one. They're just a function that happens to return JSX.

Props stopped working with this solution

Can you elaborate on that? I'm having trouble picturing what your code looks like based on that sentence.

Just confusion on my end, my mistake

@marvinhagemeister
Copy link
Collaborator

Marking as duplicate of #1540

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

3 participants