Loading the Subscription Manager inside a Single-Page App
Loading the Subscription Manager inside a Single-Page App
Prevent stale data and re-firing notifications when navigating in React and other SPAs
The Ordergroove Subscription Manager (SM) uses a singleton data store. When loading the SM inside a single-page app (e.g. built with React), you may notice odd behavior when navigating away from and back to the SM. For example, the order data may be stale, or previous toast notifications may re-fire. This is because the SM data store only reinitializes when the page does a full reload, not on client-side navigations. When you navigate back to the page it uses the same data as the initial load.
To reinitialize the SM data store without a full page reload and prevent issues with stale data, call window.og.smi.reset() whenever you navigate back to the page that loads the SM.
For example, this is what that could look like in a React component: