@anker-in/shopify-react 0.1.1-beta.30 → 0.1.1-beta.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -148,14 +148,25 @@ declare function CartProvider({ children, autoFreeGiftConfig, gradientGiftsConfi
148
148
  /**
149
149
  * Hook to access cart context
150
150
  *
151
- * @throws Error if used outside CartProvider
152
- * @returns Cart context value
151
+ * @param options - Optional configuration
152
+ * @param options.optional - If true, returns undefined instead of throwing error when used outside provider
153
+ * @throws Error if used outside CartProvider (unless optional is true)
154
+ * @returns Cart context value (or undefined if optional is true and no provider exists)
153
155
  *
154
156
  * @example
155
157
  * ```tsx
156
158
  * const { cart, mutateCart, isCartLoading, loadingState } = useCartContext()
159
+ *
160
+ * // Optional usage (safe for SSR)
161
+ * const cartContext = useCartContext({ optional: true })
162
+ * if (cartContext) {
163
+ * const { cart } = cartContext
164
+ * }
157
165
  * ```
158
166
  */
159
167
  declare function useCartContext(): CartContextValue;
168
+ declare function useCartContext(options: {
169
+ optional: true;
170
+ }): CartContextValue | null;
160
171
 
161
172
  export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
@@ -148,14 +148,25 @@ declare function CartProvider({ children, autoFreeGiftConfig, gradientGiftsConfi
148
148
  /**
149
149
  * Hook to access cart context
150
150
  *
151
- * @throws Error if used outside CartProvider
152
- * @returns Cart context value
151
+ * @param options - Optional configuration
152
+ * @param options.optional - If true, returns undefined instead of throwing error when used outside provider
153
+ * @throws Error if used outside CartProvider (unless optional is true)
154
+ * @returns Cart context value (or undefined if optional is true and no provider exists)
153
155
  *
154
156
  * @example
155
157
  * ```tsx
156
158
  * const { cart, mutateCart, isCartLoading, loadingState } = useCartContext()
159
+ *
160
+ * // Optional usage (safe for SSR)
161
+ * const cartContext = useCartContext({ optional: true })
162
+ * if (cartContext) {
163
+ * const { cart } = cartContext
164
+ * }
157
165
  * ```
158
166
  */
159
167
  declare function useCartContext(): CartContextValue;
168
+ declare function useCartContext(options: {
169
+ optional: true;
170
+ }): CartContextValue | null;
160
171
 
161
172
  export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
@@ -699,7 +699,7 @@ function useUpdateCartAttributes(mutate, metafieldIdentifiers, options) {
699
699
  }
700
700
  return updatedCart;
701
701
  },
702
- [client, locale, cartCookieAdapter, mutate]
702
+ [client, locale, cartCookieAdapter, mutate, metafieldIdentifiers]
703
703
  );
704
704
  return useSWRMutation8__default.default("update-cart-attributes", updateAttributes, options);
705
705
  }
@@ -735,7 +735,7 @@ function useHasPlusMemberInCart({
735
735
  }, [cart?.lineItems, plus_monthly_product, plus_annual_product]);
736
736
  }
737
737
  var getReferralAttributes = () => {
738
- const inviteCode = shopifySdk.getLocalStorage("invite_code") || Cookies5__default.default.get("invite_code");
738
+ const inviteCode = shopifySdk.getLocalStorage("inviteCode") || Cookies5__default.default.get("inviteCode");
739
739
  const playModeId = shopifySdk.getLocalStorage("playModeId") || Cookies5__default.default.get("playModeId");
740
740
  const popup = shopifySdk.getLocalStorage("_popup") || Cookies5__default.default.get("_popup");
741
741
  if (inviteCode && playModeId) {
@@ -1282,9 +1282,9 @@ function CartProvider({
1282
1282
  );
1283
1283
  return /* @__PURE__ */ jsxRuntime.jsx(CartContext.Provider, { value, children });
1284
1284
  }
1285
- function useCartContext() {
1285
+ function useCartContext(options) {
1286
1286
  const context = react.useContext(CartContext);
1287
- if (!context) {
1287
+ if (!context && !options?.optional) {
1288
1288
  throw new Error("useCartContext must be used within a CartProvider");
1289
1289
  }
1290
1290
  return context;