Is it possible to invalidate cache from another microfrontend RTK-query

Viewed 14

I have a micro-frontend 1 that is using RTK-query and micro-frontend 2 which just a general react application. In theory, I would like for MF-2 to make some api (Post/Put) calls that should invalidate a query from MF-1. I'm wondering if this would actually work ? Can a separate service invalidate the cache of another so they can be in sync ?

1 Answers

It's possible to programmatically invalidate an API endpoint, if you have access to the Redux store and the API slice object and can dispatch actions:

store.dispatch(
  api.util.invalidateTags(['Post']))
)

So yes, if your MF-2 can get access to the store from MF-1 somehow, or you can expose some kind of method or event emitter from MF-1 that wraps that "invalidate" logic, this can work.

See https://redux-toolkit.js.org/rtk-query/api/created-api/api-slice-utils#invalidatetags

Related