DEV Community

Discussion on: Normalize your React Query data with MobX State Tree

Collapse
 
hrastnik profile image
Mateo Hrastnik • Edited

Or does the React Query cache reference the MobX cache so whenever you update data in MobX, the change propagates to the React Query cache

Exactly. The data lives only in MobX. React Query caches only the references to the MST instances, so if you update the data anywhere, the change is visible everywhere.

how do you update data in your server data with a MobX action

You can use react-query mutations, and then update the MobX data once the request is successful.
Mutations are really practical as they handle the IDLE > LOADING > SUCCESS | ERROR state transitions and support retries and other react query goodies. However, you can just as simply run your async actions in useEffect.