To use the React SDK, install the @wix/sdk-react package using npm or Yarn:
Copy Code
npm install @wix/sdk-react
or
Copy Code
yarn add @wix/sdk-react
Then import WixProvider
along with other functionality you need from @wix/sdk-react
, including an authentication strategy and the hooks you'll use:
Copy Code
import { WixProvider, OAuthStrategy, useWixModules } from '@wix/sdk-react';
Next, add a WixProvider
to your React project an set the authentication information:
Copy Code
<WixProviderauth={OAuthStrategy({clientId: '<CLIENT_ID>',})}></WixProvider>
Finally, call the useWixModules()
hook within the WixProvider
to get an initialized instance of a Wix SDK module and call its functions:
Copy Code
import { products } from '@wix/stores';//...const { queryProducts } = useWixModules(products);const { items: productList } = await queryProducts().find();
Was this helpful?