Search code examples
reactjsrtk-query

How to generate a custom cache entry on RTK query without async calls


I have a micro-frontend architecture and I'd like to understand if it is possible to update the cache of RTK query in a custom way without doing an API Call.

I'm using Single-SPA to implement my micro-frontend architecture and from the micro-frontend that act as the orchestrator all the other micro-frontends receive a JSON representing some shared info that must be fetched only once and then shared with the other micro-frontends. I need to write that shared info into the RTK query's cache so I tried the following:

useEffect(() =>{
  apiSlice.util.updateQueryData('getInfo', undefiend, (draft) => Object.assign(draft, info))
},[])

This won't work because (from Github)

updateQueryData only updates existing data for existing cache entries. It is not meant to add new cache entries.

Is what I'm trying to do possibile with RTK query or do I have to dispatch normal action and write normally the data I want on Redux ?


Solution

  • At the moment (RTK 1.8), there is no support for this. There is an open PR, but that still needs some work.