PierreP
Convex Communityβ€’2y agoβ€’
2 replies
Pierre

Same query used multiple times

Context: The result of a query is used quite a lot of time within my React-Native app, in particular into mutliple screen and deep component tree leaves. This can happen quite a lot, as in React-Native with React-Navigation, compared to the Web, you can have a lot of screens already mounted within the navigation stack (infinite in theory). And those screens subscribes to the same convex query.

Question: In that scenario, what is the good practice?
Solution 1), juste write the convex query everywhere, but with the risk of multiplicating by quite much the websocket connections. Is this correct that everytime I write "useQuery" it opens a new connection, regardless if the same query and same args is called somewhere else?

Solution 2) Introduce somehow a singleton with a state management solution. Call one time the convex query, hydrate the app global state, and components subscribe to this global state. The drawback is that it is a bit cumbersome to introduce this global state that somehow duplicate the convex one.

Which solution should would you recommend to pick?
Was this page helpful?