You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We could enable usage of the hooks logic, without importing useQuery or useSubscription.
Hooks make the code messier:
const{ posts }=useQuery()<div>// It's ambiguous what 'posts' is relating to, especially if we're calling it with arguments{posts({limit: 1}).map()}// It's super-clear when you don't have the hook{query.posts({limit: 1})}// if you want to use a field with the same arguments multiple times// we need to store it as a variableconstposts_=posts({limit: 1})// but the name conflicts with `const { posts } = useQuery()`// so we'd be better of with doingconstquery=useQuery()constposts=query.posts({limit: 1}){posts.map()}// but then the hook is redundant, we could of just imported `query` from `../src/gqless`</div>
It's possible to detect whether we're rendering inside a React Component by doing
As GQless is a proxy, we could easily do this when you do query.posts. This shouldn't be in the core though, so the core could expose an API:
// somewhere in the react bindingimport{interceptRootProxy}from'gqless'interceptRootProxy((type: "subscription"|"query")=>{// called when `query.XXX` is accessed})
inside this API, we could perform all the hook logic we currently do inside useQuery / useSubscription.
useSubscription doesn't have any arguments to customize, so it could be removed. useQuery has optional arguments, so we should make it require you to pass options
I think this should work, I'm curious to hear your thoughts
The text was updated successfully, but these errors were encountered:
Does this issue means React users has to move away from the hook pattern?
I don't think so
I don't agree with the proposal made here, there is component-aware stuff in the hooks, and non-suspense usage, which this pattern wouldn't allow at all
@samdenty If you want to make a separate branch implementing this logic as a proof of concept, feel free, but removing the hooks is 100% unlikely
samdenty
changed the title
Removing useQuery / useSubscription
Possible usage of hooks with useQuery / useSubscriptionApr 14, 2021
We could enable usage of the hooks logic, without importing
useQuery
oruseSubscription
.Hooks make the code messier:
It's possible to detect whether we're rendering inside a React Component by doing
As GQless is a proxy, we could easily do this when you do
query.posts
. This shouldn't be in the core though, so the core could expose an API:inside this API, we could perform all the hook logic we currently do inside
useQuery
/useSubscription
.useSubscription
doesn't have any arguments to customize, so it could be removed.useQuery
has optional arguments, so we should make it require you to pass optionsI think this should work, I'm curious to hear your thoughts
The text was updated successfully, but these errors were encountered: