How can we use redux dispatch in a query function?
Hi guys, I'm currently working on a project using redux and I want to migrate to part to tanstack query. I wanted to know if you have some insights about how can I call the dispatch function in a query function? The issue is that the dispatch function is coming from the useAppDispatch hook and since we can't use a react hook as a query function I can't use hooks inside the query function :'( Can you help me amazing devs?
4 Replies
stormy-gold•15mo ago
hi there you can create custom hook with query func
also you can use your redux inside this hook
flat-fuchsiaOP•15mo ago
Hey, thank you for your answer, but I want to use redux inside
yourQueryFn
I know I can use onSuccess but as it has been deprecated I wanted to know if there was another solutionstormy-gold•15mo ago
why do you need this if you can explain the structure to us maybe we can find another solution
flat-fuchsiaOP•15mo ago
yes of course. It's a pretty big project, I can't migrate all the project to tanstack in oneshot. There are some dependencies between each part, for instance I have a
A part
and a B part
, at the end of the A part
i need to call a function of the B part
. For now I only have migrated the A part
, so at the end of the A part
(which has been migrated to tanstack) I need to call the B part (which is still in redux)
soooo ? Do you have a suggestion? there is also the solution to pass the dispatch as a function parameter to my queryFunction