wleistra
wleistra17mo ago

Global context or shared context.

We are using react query and trpc and we ran into a undesired effect I hope someone could help me with. We have a monorepo with 20+ frontend applications (all in react/ts). Some of those apps/utilities export components that are used in other apps. Each utility/app has its own trpc server middleware for providing data to our components. Every app is wrapped in a trpc.provider and query Provider. So if we want to use a component from utility A requesting data from server A in app B we wrap that component in query provider from A. This works fine, except if app B utilizes multiple components from utility A in that case invalidating a query in one component from A, will not invalidate the other component query as both get their own context... Is there a way to share the same context somehow? 🙏
1 Reply
wleistra
wleistra17mo ago
Resolved it... One shall not recreate the queryclient for each provider instead one shall initialize it on mount