--- title: useShop description: Provides access to the `shopifyConfig` prop of ``. api_version: 2024-01 api_name: hydrogen-react source_url: html: 'https://shopify.dev/docs/api/hydrogen-react/2024-01/hooks/useshop' md: 'https://shopify.dev/docs/api/hydrogen-react/2024-01/hooks/useshop.md' --- # use​Shop Provides access to the `shopifyConfig` prop of ``. ## use​Shop() `useShop` must be a descendent of a `ShopifyProvider` component. ### Returns * ShopifyContextValue ### ShopifyContextValue * storeDomain string The full domain of your Shopify storefront URL (eg: the complete string of `{subdomain}.myshopify.com`). * storefrontToken string The Storefront API public access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. * storefrontApiVersion 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. * countryIsoCode 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`. * languageIsoCode LanguageCode `ISO 369` language codes supported by Shopify. * getStorefrontApiUrl (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 ``. However, you can override the following settings on each invocation of `getStorefrontApiUrl({...})`: * `storeDomain` - `storefrontApiVersion` * getPublicTokenHeaders (props: GetPublicTokenHeadersProps) => Record\ 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 ``. However, you can override the following settings on each invocation of `getPublicTokenHeaders({...})`: * `contentType` - `storefrontToken` * getShopifyDomain (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 ``. However, you can override the following settings on each invocation of `getShopifyDomain({...})`: * `storeDomain` * storefrontId string The globally-unique identifier for the Shop ### ShopifyContextValue * storefrontId The globally-unique identifier for the Shop ```ts string ``` * storeDomain The full domain of your Shopify storefront URL (eg: the complete string of \`{subdomain}.myshopify.com\`). ```ts string ``` * storefrontToken The Storefront API public access token. Refer to the \[authentication]\(https://shopify.dev/api/storefront#authentication) documentation for more details. ```ts string ``` * storefrontApiVersion 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. ```ts string ``` * countryIsoCode 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\`. ```ts CountryCode ``` * languageIsoCode \`ISO 369\` language codes supported by Shopify. ```ts LanguageCode ``` * getStorefrontApiUrl Creates the fully-qualified URL to your store's GraphQL endpoint. By default, it will use the config you passed in when creating \`\\`. However, you can override the following settings on each invocation of \`getStorefrontApiUrl({...})\`: - \`storeDomain\` - \`storefrontApiVersion\` ```ts (props?: GetStorefrontApiUrlProps) => string ``` * getPublicTokenHeaders 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 \`\\`. However, you can override the following settings on each invocation of \`getPublicTokenHeaders({...})\`: - \`contentType\` - \`storefrontToken\` ```ts (props: GetPublicTokenHeadersProps) => Record ``` * getShopifyDomain Creates the fully-qualified URL to your myshopify.com domain. By default, it will use the config you passed in when calling \`\\`. However, you can override the following settings on each invocation of \`getShopifyDomain({...})\`: - \`storeDomain\` ```ts (props?: GetShopifyDomainProps) => string ``` ```ts export interface ShopifyContextValue extends ShopifyProviderBase, ShopifyContextReturn {} ``` ### GetStorefrontApiUrlProps * storeDomain The host name of the domain (eg: \`{shop}.myshopify.com\`). ```ts string ``` * storefrontApiVersion 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. ```ts string ``` ```ts { /** The host name of the domain (eg: `{shop}.myshopify.com`). */ storeDomain?: 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. */ storefrontApiVersion?: string; } ``` ### GetPublicTokenHeadersProps * contentType 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"\` ```ts "json" | "graphql" ``` * storefrontToken The Storefront API access token. Refer to the \[authentication]\(https://shopify.dev/api/storefront#authentication) documentation for more details. ```ts string ``` ```ts { /** * 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"` */ contentType: 'json' | 'graphql'; /** The Storefront API access token. Refer to the [authentication](https://shopify.dev/api/storefront#authentication) documentation for more details. */ storefrontToken?: string; } ``` ### GetShopifyDomainProps * storeDomain ```ts string ``` ```ts {storeDomain?: string} ``` Examples ### Examples * #### Example code ##### Description I am the default example ##### JavaScript ```jsx import {ShopifyProvider, useShop} from '@shopify/hydrogen-react'; export default function App() { return ( ); } export function UsingUseShop() { const shop = useShop(); return ( <>
{shop.storeDomain}
{shop.storefrontToken}
{shop.storefrontApiVersion}
); } ``` ##### TypeScript ```tsx import {ShopifyProvider, useShop} from '@shopify/hydrogen-react'; export default function App() { return ( ); } export function UsingUseShop() { const shop = useShop(); return ( <>
{shop.storeDomain}
{shop.storefrontToken}
{shop.storefrontApiVersion}
); } ``` ## Related [- ShopifyProvider](https://shopify.dev/api/hydrogen-react/components/ShopifyProvider)