Closed AlmarAubel closed 1 year ago
@AlmarAubel thanks for raising this issue! I'm not familiar with the Vue API so I'm trying to understand its particularities on the example you've shared. What are the trade offs when defining queryKey: ['projects', userId]
vs queryKey: ['projects', userId.value]
Yes I understand it's very specific for Vue. Vue uses a concept called reactivity where a variable can be wrapped by a reactive object var x= ref(1)
when x is update x.value = 2
it will automatically rerender the virtual dom( or trigger other functions).
When I do userId.value it will unwrap the value an dloose the reactivity so when userId is updated it will not update the key. In vue-query it works fine. I understand that this library is framework agnostic. If I have some time left next week I will look how vue-query handles reactive var and look how it could be used to extend this framework.
In the example above the computed function return some kind of reactive var (but is read-only)
@AlmarAubel I'm preparing a new release that will support your use-case
@AlmarAubel version v1.1.0
has been released and should fix your issue!
Whoo thank you very much. Will try it out tomorrow!
Tested it this morning and the following example is working! Great work Full working example here -> https://github.com/AlmarAubel/vue-query-computed-support
const userId = ref<string>("")
const userQueries = createQueryKeys('users', {
detail: (userId: MaybeRef<string>) => ({
queryKey: [userId],
queryFn: () => getUser(unref(userId)),
}),
});
var { data, isLoading, status } = useQuery({
...userQueries.detail(userId),
enabled: computed((() => !!userId.value))
});
As a Vue user it would be really nice if I could use Computed props a key names See this example from tanstack query website ->
For example
Give the following error on
getTodo
Currently I get an type error when I translate this example to the query key factory. https://tanstack.com/query/v4/docs/vue/guides/dependent-queries