TanStackT
TanStack11mo ago
8 replies
efficient-indigo

React Query + MobX — can I (should I?) mutate query cache data directly?

We recently introduced react query to a semi-old codebase that uses MobX observables for almost everything. In MobX, state updates are done in a mutable manner.

Queries call service methods which return MobX observables and as a result the query data across our app is mostly MobX observables. I was wondering if it would be bad practice to mutate the query cache directly (since MobX observables are supposed to be mutated directly for fine grained reactivity to work), instead of doing it immutably by supplying it with completely new objects — for example, a to-do item gets checked off and we mutate its observable Todo model directly inside the "todos" query's cached array, instead of setting the query's data with a new array containing the updated item.

I am also interested in hearing about your experiences working with this library combination, or anything similar.

Thanks!
Was this page helpful?