# createCroctContext

Learn how to resolve the Croct visitor context in Remix Hydrogen apps.

This function resolves the Croct visitor context for **[Remix](https://remix.run)** Hydrogen apps, which have no route middleware.

Call it in your [`getLoadContext`](https://shopify.dev/docs/api/hydrogen/latest/utilities/createrequesthandler) wrapper, merge the returned context into the load context under the `croct` property, and call the [cookie writer](/reference/sdk/hydrogen/api/setup/write-croct-cookies) in your server entry to persist the visitor cookies on the response.

For [React Router 7](https://reactrouter.com) apps, use the [route middleware](/reference/sdk/hydrogen/api/setup/create-croct-middleware) instead.

## Signature

This function has the following signature:

```ts
function createCroctContext(
  request: Request,
  scope: ResolverContext,
  options?: CroctOptions,
): Promise<RequestContext>;
```

## Example

Resolve the context in your `getLoadContext` wrapper:

**app/lib/context.ts**

```ts
import {createCroctContext} from '@croct/plug-hydrogen/server';

const croct = await createCroctContext(request, hydrogenContext);

return {...hydrogenContext, croct};
```

## Parameters

The following list describes the supported parameters:

- `request`: `Request`

  The incoming request.

- `scope`: `ResolverContext`

  The Hydrogen context for the current request.

  The SDK reads the storefront and customer account from it to resolve the visitor identity and locale.

- `options`: `object` (optional)

  The resolver options.

  - `userIdResolver`: `(context: ResolverContext) => Promise<string | null>` (optional)

    The function that resolves the ID of the logged-in customer for the current request.

    It receives the [Hydrogen request context](/reference/sdk/hydrogen/api/types/resolver-context) and returns the user ID, or nothing for anonymous visitors.

    By default, the SDK reads the logged-in customer's ID from the Shopify Customer Account API.

  - `localeResolver`: `(context: ResolverContext) => Promise<string | null>` (optional)

    The function that resolves the preferred content locale for the current request.

    It receives the [Hydrogen request context](/reference/sdk/hydrogen/api/types/resolver-context) and returns a [BCP‑47](https://www.rfc-editor.org/info/bcp47) locale, or nothing to use the workspace default.

    By default, the SDK derives the locale from the storefront's `i18n` configuration, such as `en-US`.
