This module is deprecated. For more information, see Migrating from sdk-react.
To use the React SDK, install the @wix/sdk-react
package:
npm install @wix/sdk-react
Or
yarn add @wix/sdk-react
Then, import WixProvider
, the authentication strategy to use, and any relevant hooks, like useWixModules:
import {
WixProvider,
OAuthStrategy,
AppStrategy,
useWixModules,
} from "@wix/sdk-react";
Next, wrap your app in a WixProvider
initialized with the appropriate authentication strategy:
Note: In most scenarios, the React SDK is used on client environments such as browsers and mobile apps. To ensure security, we recommend not to expose API keys in such environments given their administrative permissions. For more information, see Authorization Strategies.
Finally, to get an initialized instance of a Wix SDK module and call its functions, call the useWixModules()
hook within the WixProvider
:
import { products } from "@wix/stores";
//...
const { queryProducts } = useWixModules(products);
const { items: productList } = await queryProducts().find();