Skip to content

Commit

Permalink
Make <CartProvider> use country code from <ShopifyProvider> (#2521)
Browse files Browse the repository at this point in the history
  • Loading branch information
blittle committed Jun 5, 2023
1 parent be4eab1 commit ca65e24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilly-dogs-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Fix the `<CartProvider>` to by default pull localization from `<ShopifyProvider>`. You can still override the countryCode by passing a prop directly to `<CartProvider>`. Resolves https://github.com/Shopify/hydrogen/issues/622
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {CartNoteUpdateMutationVariables} from './graphql/CartNoteUpdateMutation.
import {useCartAPIStateMachine} from './useCartAPIStateMachine.client.js';
import {CART_ID_STORAGE_KEY} from './constants.js';
import {ClientAnalytics} from '../../foundation/Analytics/ClientAnalytics.js';
import {useLocalization} from '../../hooks/useLocalization/useLocalization.js';

export function CartProvider({
children,
Expand All @@ -57,7 +58,7 @@ export function CartProvider({
data: cart,
cartFragment = defaultCartFragment,
customerAccessToken,
countryCode = CountryCode.Us,
countryCode,
}: {
/** Any `ReactNode` elements. */
children: React.ReactNode;
Expand Down Expand Up @@ -104,6 +105,12 @@ export function CartProvider({
/** The ISO country code for i18n. */
countryCode?: CountryCode;
}) {
const {country} = useLocalization();

countryCode = (
(countryCode as string) ?? country.isoCode
).toUpperCase() as CountryCode;

if (countryCode) countryCode = countryCode.toUpperCase() as CountryCode;
const [prevCountryCode, setPrevCountryCode] = useState(countryCode);
const [prevCustomerAccessToken, setPrevCustomerAccessToken] =
Expand Down

0 comments on commit ca65e24

Please sign in to comment.