fresh icon indicating copy to clipboard operation
fresh copied to clipboard

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

Open echoptic opened this issue 2 years ago • 5 comments

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)
    ``` 

echoptic avatar Aug 17 '23 09:08 echoptic

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 avatar Aug 17 '23 10:08 marvinhagemeister

Related https://github.com/denoland/fresh/issues/1540

marvinhagemeister avatar Aug 17 '23 10:08 marvinhagemeister

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

pnadj avatar Oct 24 '23 20:10 pnadj

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.

marvinhagemeister avatar Oct 25 '23 15:10 marvinhagemeister

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

pnadj avatar Oct 25 '23 15:10 pnadj

Marking as duplicate of https://github.com/denoland/fresh/issues/1540

marvinhagemeister avatar Mar 12 '24 11:03 marvinhagemeister