Skip to content

Commit d06e687

Browse files
docs: adjust createAlokaiContext method (#7363)
1 parent 5032bff commit d06e687

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

Diff for: docs/content/4.sdk/2.getting-started/1.index.md

+23-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ If you're setting your Alokai application from scratch, you'll need to configure
66
In the examples below, we assume that you have an Alokai app with the Unified Data Model. However, the approach for non-unified Alokai applications is similar.
77
:::
88

9-
There are various ways to configure the SDK, depending on your chosen framework. For Next.js and Nuxt, you can use the `@vue-storefront/next` and `@vue-storefront/nuxt` packages respectively.
9+
There are various ways to configure the SDK, depending on your chosen framework. For Next.js and Nuxt, you can use the `@vue-storefront/next` and `@vue-storefront/nuxt` packages respectively.
1010
These packages also provide tools for handling the global state management.
1111

1212
If you're looking for framework agnostic experience, you can use the `@vue-storefront/sdk` package.
@@ -174,15 +174,34 @@ To use it, you'll need to create a new file in your application, for example `sd
174174
'use client';
175175

176176
import { createAlokaiContext } from '@vue-storefront/next/client';
177+
import type { SfContract } from 'storefront-middleware/types';
177178

178179
import type { Sdk } from './sdk.server';
179180

180-
export const { AlokaiProvider, useSdk } = createAlokaiContext<Sdk>();
181+
export const {
182+
AlokaiProvider,
183+
useSdk,
184+
useSfCartState,
185+
useSfCurrenciesState,
186+
useSfCurrencyState,
187+
useSfCustomerState,
188+
useSfLocaleState,
189+
useSfLocalesState,
190+
} = createAlokaiContext<Sdk, SfContract>();
181191
```
182192

183-
This is also a place where you can import hooks for handling the state management. You can read more about the state management in the [State Management](/sdk/getting-started/state-management) page.
193+
The `SfContract` interface is used to define the contract between the SDK and the state management. It contains the types for:
184194

185-
Once you have created the Alokai context, you can create client-side SDK instance and register it in your application.
195+
- cart (`SfCart` type)
196+
- customer (`SfCurrency` type)
197+
- currency (`SfCurrency` type)
198+
- locale (`SfLocale` type)
199+
200+
This is needed to ensure that the state management is aware of the types that you have within the middleware, as those types can be changed within the middleware.
201+
202+
You can read more about the state management in the [State Management](/sdk/getting-started/state-management) page.
203+
204+
Once you have created the Alokai context, you can create client-side SDK instance and register it in your application.
186205

187206
You can do it in two steps:
188207

0 commit comments

Comments
 (0)