I'm using RTK Query in my app. I have some filters on a page. I want to keep them in store so that if I leave page and come back they would stay the same. So when user changes them in select dropdowns app dispatches some reducer's action.
How can I subscribe to those filters changed and make RTK Query after filters have been changed? So it would be subsription to changes of some slice's piece of state, which would trigger rtk query request
Asked
Active
Viewed 208 times
-1

PttRulez
- 115
- 7
1 Answers
1
You mean like this?
const filterValueFromStore = useSelector(state => state.foo.bar)
const result = useSomeQuery({ someFilter: filterValueFromStore })

phry
- 35,762
- 5
- 67
- 81
-
Something like that. In your example, will it trigger SomeQuery any time when filterValueFromStore is changed by 'foo' reducer? By the way I have handle it with useLazySomeQuery. And subscribed to filter changes in useEffect - is it good practice? – PttRulez Jan 22 '23 at 14:46
-
May be I missed it in docs. if queryArg has changed does it trigger new auto fetch? – PttRulez Jan 22 '23 at 14:58
-
Yes, if the argument changes, it will make a new request. – phry Jan 22 '23 at 15:57