Exposing queryKey as an argument in placeholderData & initialData functions #9127
-
Firstly, Levaraging the Query Function Context is a great blog post that explains the possible closure problems with queryFn. Thanks for that. After reading the post, I was wondering if the same can be considered with // query hook
const someUuid = useSomeUuid()
const anotherUuid = useAnotherUuid()
return useQuery({
queryFn,
queryKey: queryKeyFactory.get(someUuid,anotherUuid),
placeholderData: (queryKey) => { // Here, does it make sense to expose queryKey
// if I try to use `someUuid` or `anotherUuid`, placeholderData function creates a closure over it(?)
const anotherUuid = queryKey[1]
const data = queryClient.getQueryData(
queryKeyFactory.getAnotherOne(anotherUuid)
.....
},
}) Please consider the example as a non-working example. Does this make sense? Could this be considered as an additional feature in react query? I would love to hear back some thoughts on it. Thanks! PS: If same idea was thrown out by someone else before, feel free to close this one. Sorry in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
why would you need the queryKey if you could also do:
and then you can close over the queryKey just fine? |
Beta Was this translation helpful? Give feedback.
placeholderData
already gets two params -(previousData, previousQuery)
why would you need the queryKey if you could also do:
and then you can close over the queryKey just fine?