Setup
To use the React SDK, install the @wix/sdk-react
package:
Copy
1npm install @wix/sdk-react
Or
Copy
1yarn add @wix/sdk-react
Then, import WixProvider
, the authentication strategy to use, and any relevant hooks, like useWixModules:
Copy
1import { WixProvider, OAuthStrategy, AppOAuthStrategy, useWixModules } from '@wix/sdk-react';
Next, wrap your app in a WixProvider
initialized with the appropriate authentication strategy:
- ApiKeyStrategy: Use for admin operations.
- OAuthStrategy: Use for Wix Headless sites.
- AppOAuthStrategy: Use for Wix apps.
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
:
Copy
1import { products } from '@wix/stores';2
3//...4
5const { queryProducts } = useWixModules(products);6
7const { items: productList } = await queryProducts().find();
Was this helpful?
Yes
No