@chec/react-commercejs-hooks
Version:
ReactJS hooks for using Commerce.js with React projects
20 lines (19 loc) • 792 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var useCommerce_1 = __importDefault(require("../useCommerce"));
var js_cookie_1 = __importDefault(require("js-cookie"));
/**
* Returns a string cart ID, or null if Commerce.js is not available
*/
function useActiveCartId() {
var commerce = useCommerce_1.default();
if (commerce && commerce.cart) {
// Fallback to accessing the cookie ourselves, as the implementation provided by Commerce.js itself is a bit flakey
return commerce.cart.id() || js_cookie_1.default.get('commercejs_cart_id');
}
return null;
}
exports.default = useActiveCartId;