Replies: 2 comments 2 replies
-
You can use the In case the cache hit is required, let's use the predicate options const listener = createListenerMiddleware()
listener.startListening({
predicate: (action, state, prevState)=>{ return api.endpoints.getSomething.matchFulfilled(state) const params= getParams(action)
const matched = api.endpoints.getSomething.matchFulfilled(action)
const { data } = api.endpoints.getSomething.select(params)(prevState)
return matched && !!data
},
effect: async (action, api) => {}
) |
Beta Was this translation helpful? Give feedback.
2 replies
-
As mentioned by @markerikson there is not an action dispatched for a cache hit. However, maybe this pattern could help where you dispatch an action related to the arg changing instead, obviously this is dependant on your situation, and you may need some additional predicate or conditional in your middleware. const mySlice = createSlice({
initialState: { arg: null },
reducers: {
argChanged(state, action) {
state.arg = action.payload
}
},
selectors: {
selectMyArg: state => state.arg
}
}) const arg = useSelector(selectMyArg)
const { data } = useMyQuery(arg)
function onClick() {
dispatch(argChanged(newArg))
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello community! I come here with a scenario and a question:
A basic RTK Query setup (with a tag in the param sent as a string):
My middleware listener:
A basic component:
So my issue is the following:
Is there any matcher for cache hits that I can use in my middleware for this scenario?
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions