# useShop Provides access to the `shopifyConfig` prop of `<ShopifyProvider/>`. ### Example code ```jsx import {ShopifyProvider, useShop} from '@shopify/hydrogen-react'; export default function App() { return ( <ShopifyProvider storeDomain="my-store" storefrontToken="abc123" storefrontApiVersion="2022-10" countryIsoCode="CA" languageIsoCode="EN" > <UsingUseShop /> </ShopifyProvider> ); } export function UsingUseShop() { const shop = useShop(); return ( <> <div>{shop.storeDomain}</div> <div>{shop.storefrontToken}</div> <div>{shop.storefrontApiVersion}</div> </> ); } ``` ```tsx import {ShopifyProvider, useShop} from '@shopify/hydrogen-react'; export default function App() { return ( <ShopifyProvider storeDomain="my-store" storefrontToken="abc123" storefrontApiVersion="2022-10" countryIsoCode="CA" languageIsoCode="EN" > <UsingUseShop /> </ShopifyProvider> ); } export function UsingUseShop() { const shop = useShop(); return ( <> <div>{shop.storeDomain}</div> <div>{shop.storefrontToken}</div> <div>{shop.storefrontApiVersion}</div> </> ); } ``` ## Props `useShop` must be a descendent of a `ShopifyProvider` component. ### UseShopGeneratedType Provides access to the `shopifyConfig` prop of `<ShopifyProvider/>`. Must be a descendent of `<ShopifyProvider/>`. #### Returns: ShopifyContextValue export function useShop(): ShopifyContextValue { const shopContext = useContext(ShopifyContext); if (!shopContext) { throw new Error(`'useShop()' must be a descendent of <ShopifyProvider/>`); } return shopContext; } ### ShopifyContextValue ### countryIsoCode value: `CountryCode` The code designating a country, which generally follows ISO 3166-1 alpha-2 guidelines. If a territory doesn't have a country code value in the `CountryCode` enum, it might be considered a subdivision of another country. For example, the territories associated with Spain are represented by the country code `ES`, and the territories associated with the United States of America are represented by the country code `US`. ### getPublicTokenHeaders value: `(props: GetPublicTokenHeadersProps) => Record<string, string>` Returns an object that contains headers that are needed for each query to Storefront API GraphQL endpoint. This uses the public Storefront API token. By default, it will use the config you passed in when creating `<ShopifyProvider/>`. However, you can override the following settings on each invocation of `getPublicTokenHeaders({...})`: - `contentType` - `storefrontToken` ### getShopifyDomain value: `(props?: GetShopifyDomainProps) => string` Creates the fully-qualified URL to your myshopify.com domain. By default, it will use the config you passed in when calling `<ShopifyProvider/>`. However, you can override the following settings on each invocation of `getShopifyDomain({...})`: - `storeDomain` ### getStorefrontApiUrl value: `(props?: GetStorefrontApiUrlProps) => string` Creates the fully-qualified URL to your store's GraphQL endpoint. By default, it will use the config you passed in when creating `<ShopifyProvider/>`. However, you can override the following settings on each invocation of `getStorefrontApiUrl({...})`: - `storeDomain` - `storefrontApiVersion` ### languageIsoCode value: `LanguageCode` `ISO 369` language codes supported by Shopify. ### storeDomain value: `string` The full domain of your Shopify storefront URL (eg: the complete string of `{subdomain}.myshopify.com`). ### storefrontApiVersion value: `string` The Storefront API version. This should almost always be the same as the version Hydrogen React was built for. Learn more about Shopify [API versioning](https://shopify.dev/api/usage/versioning) for more details. ### storefrontId value: `string` The globally-unique identifier for the Shop ### storefrontToken value: `string` The Storefront API public access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. ### GetPublicTokenHeadersProps ### contentType value: `'json' | 'graphql'` Customizes which `"content-type"` header is added when using `getPrivateTokenHeaders()` and `getPublicTokenHeaders()`. When fetching with a `JSON.stringify()`-ed `body`, use `"json"`. When fetching with a `body` that is a plain string, use `"graphql"`. Defaults to `"json"` ### storefrontToken value: `string` The Storefront API access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. ### GetShopifyDomainProps ### storeDomain value: `string` ### GetStorefrontApiUrlProps ### storeDomain value: `string` The host name of the domain (eg: `{shop}.myshopify.com`). ### storefrontApiVersion value: `string` The Storefront API version. This should almost always be the same as the version Hydrogen-UI was built for. Learn more about Shopify [API versioning](https://shopify.dev/api/usage/versioning) for more details. ## Related - [ShopifyProvider](/api/hydrogen-react/components/ShopifyProvider)