--- title: cartSetIdDefault description: Creates a function that returns a header with a Set-Cookie on the cart ID. api_version: 2025-07 api_name: hydrogen source_url: html: https://shopify.dev/docs/api/hydrogen/latest/utilities/cartsetiddefault md: https://shopify.dev/docs/api/hydrogen/latest/utilities/cartsetiddefault.md --- # cart​Set​Id​Default Creates a function that returns a header with a Set-Cookie on the cart ID. ## cart​Set​Id​Default([cookieOptions](#cartsetiddefault-propertydetail-cookieoptions)​) ### Parameters * cookieOptions CookieOptions ### CookieOptions * domain ```ts string ``` * expires ```ts Date | number | string ``` * httponly ```ts boolean ``` * maxage ```ts number ``` * path ```ts string ``` * samesite ```ts 'Lax' | 'Strict' | 'None' ``` * secure ```ts boolean ``` ```ts { maxage?: number; expires?: Date | number | string; samesite?: 'Lax' | 'Strict' | 'None'; secure?: boolean; httponly?: boolean; domain?: string; path?: string; } ``` Examples ### Examples * #### example ##### Description This is the default example ##### JavaScript ```js import {data} from 'react-router'; import {cartGetIdDefault, cartSetIdDefault} from '@shopify/hydrogen'; // server.js export default { async fetch(request) { const cart = createCartHandler({ storefront, getCartId: cartGetIdDefault(request.headers), setCartId: cartSetIdDefault(), // defaults to session cookie // setCartId: cartSetIdDefault({maxage: 60 * 60 * 24 * 365}), // 1 year expiry }); }, }; // Some route export async function action({context}) { const {cart} = context; // Usage const result = await cart.updateNote('Some note'); const headers = cart.setCartId(result.cart.id); return data(result, {headers}); } ```