Skip to content

Commit

Permalink
docs: add docs for createSdkContext
Browse files Browse the repository at this point in the history
  • Loading branch information
jagoral committed Dec 18, 2023
1 parent a6b6c15 commit ca4eeb6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/storefront/packages/next/src/sdk/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ import Script from "next/script";
import React, { createContext, useContext } from "react";
import { SdkProviderProps } from "./types";

/**
* Creates a new SDK context. This function is dedicated for the client-side usage.
*
* @example
* Create a new SDK context somewhere in your application. It may be the `hooks/sdk.ts` file.
*
* ```tsx
* import { createSdkContext } from "@vue-storefront/next/client";
* import { getSdk } from "../../sdk.config.ts";
*
* export const [SdkProvider, useSdk] = createSdkContext(getSdk());
* ```
* Then use the `SdkProvider` in the root component of your application.
* For Pages Router it would be the `pages/_app.tsx` file,
* and for the App Router it would be the `app/layout.tsx` file.
* Finally you can use the `useSdk` in any client component of your application.
* @returns [SdkProvider, useSdk] - The SDK provider and the `useSdk` hook.
*/
export function createSdkContext<TSdk extends SDKApi<any>>(sdk: TSdk) {
const SdkContext = createContext<TSdk>(sdk);

Expand Down

0 comments on commit ca4eeb6

Please sign in to comment.