Store

The Snipcart SDK uses Redux as a state management tool. Therefore, some of the Redux's store methods are available to you.

getState

The getState method returns the current state tree of the application. In this case, the return value is of type SnipcartState.

Snipcart.store.getState();

subscribe

The subscribe method triggers a callback every time an action is dispatched. It is often used to check if a change occurred in the state of the application. When invoked, the return function of the subscribe method will remove the change listener.

let currentValue;
const unsubscribe = store.subscribe(() => {
    let previousValue = currentValue;
    currentValue = Snipcart.store.getState();

    if (previousValue !== currentValue) {
        // Anything goes...
    }
});

// unsubscribe();