Invalidate a tag on every mutation from code generated RTK Query base #3926
-
I'm code generating RTK Query based on a OPENapi definition. There are some 30 tags with each one supplying multiple endpoints, pretty typical CRUD stuff. One endpoint fetches a validation on the state of the whole system ( it is essentially a multi part form type of thing ) which I want to invalidate each time there is a mutation in addition to invalidating their standard tag type. I'm asking for the best way to approach this. Here are some solutions I could think of but someone familiar with RTK Query could see what the best option is (probably not one of mine).
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I ended up going for the middleware export const validationMiddleware: Middleware =
(api: MiddlewareAPI) => (next) => (action) => {
if (isFulfilled(action) && action.meta.arg.type === 'mutation') {
api.dispatch(rtkApi.util.invalidateTags(['Validation']))
}
return next(action)
} |
Beta Was this translation helpful? Give feedback.
I ended up going for the middleware