use Shopify Cookieshooks
hooks
Sets Shopify user and session cookies and refreshes the expiry time.
Manages Shopify cookies. If option is false, Shopify cookies will be removed.
Anchor to useShopifyCookies-parametersParameters
- UseShopifyCookiesOptions
Anchor to useShopifyCookies-returnsReturnsvoid
void
UseShopifyCookiesOptions
- checkoutDomain
The checkout domain of the shop. Defaults to empty string. If set, the cookie domain will check if it can be set with the checkout domain.
string
- domain
The domain scope of the cookie. Defaults to empty string.
string
- hasUserConsent
If set to `false`, Shopify cookies will be removed. If set to `true`, Shopify unique user token cookie will have cookie expiry of 1 year. Defaults to false.
boolean
{
/**
* If set to `false`, Shopify cookies will be removed.
* If set to `true`, Shopify unique user token cookie will have cookie expiry of 1 year.
* Defaults to false.
**/
hasUserConsent?: boolean;
/**
* The domain scope of the cookie. Defaults to empty string.
**/
domain?: string;
/**
* The checkout domain of the shop. Defaults to empty string. If set, the cookie domain will check if it can be set with the checkout domain.
*/
checkoutDomain?: string;
}
Was this section helpful?
Example code
import * as React from 'react';
import {useShopifyCookies} from '@shopify/hydrogen-react';
export default function App({Component, pageProps}) {
useShopifyCookies({hasUserConsent: false});
return <Component {...pageProps} />;
}
Examples
Example code
Description
I am the default example
JavaScript
import * as React from 'react'; import {useShopifyCookies} from '@shopify/hydrogen-react'; export default function App({Component, pageProps}) { useShopifyCookies({hasUserConsent: false}); return <Component {...pageProps} />; }
TypeScript
import * as React from 'react'; import {useShopifyCookies} from '@shopify/hydrogen-react'; export default function App({Component, pageProps}) { useShopifyCookies({hasUserConsent: false}); return <Component {...pageProps} />; }