[✨] Let us use your custom hooks, inside the routeLoader$ too #151
Replies: 7 comments
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
I have the same request. Currently my component uses hook for graphql integration but the hook cannot be used inside I can see one problem of allowing hooks outside component is reactivity state. If the hook contains signals, not sure how it will be. |
Beta Was this translation helpful? Give feedback.
-
|
I also need this features. I'm trying to access URL inside my custom hook. |
Beta Was this translation helpful? Give feedback.
-
|
@Nefcanto how did you solve this specific task? |
Beta Was this translation helpful? Give feedback.
-
|
@gioboa, sorry to answer this late. Right now we have to do props drilling. We load some data from the API in |
Beta Was this translation helpful? Give feedback.
-
|
Actually there's no reason to confine signals to the render tree, but there can be no reactivity between server and client (that requires a communication channel). Hooks could be made possible inside loaders, but they would not see any context and they would run fresh every time. So if you want to use a graphql hook inside route loaders, that would technically be possible, but it would be adding some overhead for no reason, and you'd have to put the client provider just before the query. So it would look weird, and it would be a little inefficient. |
Beta Was this translation helpful? Give feedback.
-
|
We moved this issue to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem?
I want to centralize some code that is used across many
routeLoader$instances. I'm using custom hooks to do that. And inside my custom hook, I'm using your hooks to access URL data (query string in this case).But I get this error:
The error message is crystal clear. I should use your hooks only inside
component$. However, a lot of times we need to centralize code in our manyrouteLoader$functions too. I have created an instance for this:stackblitz
I know that I can access
requestEventfrom inside therouteLoader$and pass it to my custom hook. I know that. But that's not clean.Please let us write this code:
Describe the solution you'd like
I would like to be able to call your custom hooks inside our custom hooks, and then use our custom hooks inside the
routeLoader$function.Describe alternatives you've considered
For now, we repeat ourselves. We write this code in every page and in every layout code:
Additional context
Please see the example link above and uncomment the
getDatafunction in theindex.tsxfile.Beta Was this translation helpful? Give feedback.
All reactions