# useShopifyCookies
Sets Shopify user and session cookies and refreshes the expiry time.
```jsx
import * as React from 'react';
import {useShopifyCookies} from '@shopify/hydrogen';
export default function App({Component, pageProps}) {
useShopifyCookies({hasUserConsent: false});
return ;
}
```
```tsx
import * as React from 'react';
import {useShopifyCookies} from '@shopify/hydrogen';
export default function App({Component, pageProps}) {
useShopifyCookies({hasUserConsent: false});
return ;
}
```
## useShopifyCookies
Manages Shopify cookies. If `hasUserConsent` option is false, Shopify cookies will be removed.
### UseShopifyCookiesGeneratedType
#### Returns: void
#### Params:
- options: UseShopifyCookiesOptions
export function useShopifyCookies(options?: UseShopifyCookiesOptions): void {
const {hasUserConsent = false, domain = ''} = options || {};
useEffect(() => {
const cookies = getShopifyCookies(document.cookie);
/**
* Set user and session cookies and refresh the expiry time
*/
if (hasUserConsent) {
setCookie(
SHOPIFY_Y,
cookies[SHOPIFY_Y] || buildUUID(),
longTermLength,
domain,
);
setCookie(
SHOPIFY_S,
cookies[SHOPIFY_S] || buildUUID(),
shortTermLength,
domain,
);
} else {
setCookie(SHOPIFY_Y, '', 0, domain);
setCookie(SHOPIFY_S, '', 0, domain);
}
});
}
### UseShopifyCookiesOptions
### hasUserConsent
value: `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.
### domain
value: `string`
The domain scope of the cookie. Defaults to empty string.
## Related
- [sendShopifyAnalytics](/api/hydrogen/utilities/sendShopifyAnalytics)
- [getClientBrowserParameters](/api/hydrogen/utilities/getclientbrowserparameters)
- [getShopifyCookies](/api/hydrogen/utilities/getShopifyCookies)