Apollo Client Reactive Variables state persistence during page refreshes
0 reputation · 12 Mar 2025, 00:42 UTC
Local State Management
Apollo Client's Reactive Variables provide a mechanism to manage global client-side state outside of the normalized cache. Using makeVar, developers can create variables that trigger component re-renders via the useReactiveVar hook without requiring a remote GraphQL server or network requests.
Persistence Constraints
By design, Reactive Variables are stored in memory. This creates a discrepancy in user experience when a browser refresh occurs, as the local state is reset to its initial value, unlike the Apollo Cache which can be integrated with persistence layers.
When designing a system that requires local state to survive a session reload, it is unclear how to best synchronize these variables with browser storage APIs without introducing redundant state logic or manual synchronization boilerplate.
- What is the recommended pattern for integrating Reactive Variables with
localStorageto ensure state persistence across page refreshes? - Does Apollo Client provide a built-in mechanism to hydrate Reactive Variables from a persisted source during initialization?