react-apollo-hooks icon indicating copy to clipboard operation
react-apollo-hooks copied to clipboard

api ergonomics

Open kyunghoon opened this issue 6 years ago • 1 comments

instead of returning an object from useQuery/useSubscription, (given that the number of parameters and their function do not change) returning a tuple(array) would allow users to de-structure the variable names as they see fit, similarly along the lines of useState. it would allow multiple queries from the same function without name collisions and extra noise from additional temporary variables.

kyunghoon avatar Jun 11 '19 02:06 kyunghoon

Hi @kyunghoon

I don't think this would be a very good idea because useQuery returns a lot of things. It returns loading, data, refetch, error, networkStatus, ..., just imagine having to define the right order for that.

If all you want to do is to rename the properties you can do it pretty easily using this form: const { data: otherNameForData } = useQuery(...)

For me info check this post: https://wesbos.com/destructuring-renaming/

jzabala avatar Jun 14 '19 03:06 jzabala