Skip to main content

React SDK

The React SDK is a collection of components and hooks that can be used to build React applications that interact with the ComPilot Widget

Installation

The React SDK can be installed with yarn, npm, or pnpm.

yarn add @compilot/react-sdk

Usage

Create a configuration object

Add the ComPilotProvider

First add the ComPilotProvider at the root of your application.

import { ComPilotProvider } from "@compilot/react-sdk";

import { config } from "./config";

function App() {
return <ComPilotProvider>{/* Your application */}</ComPilotProvider>;
}

Then you can use any of the hooks provided by the SDK to interact with the ComPilot Widget.

import {
useCustomerStatus,
useIsAuthenticated,
useIsLoading,
useOpenWidget,
} from "@compilot/react-sdk";

function MyComponent() {
const authenticate = useAuthenticate();
const isAuthenticated = authenticate.data === true;
const isLoading = authenticate.isPending;
const openWidget = useOpenWidget();
const customerStatus = useCustomerStatus();

return (
<div>
<p>Is authenticated: {isAuthenticated ? "Yes" : "No"}</p>
<p>Is loading: {isLoading ? "Yes" : "No"}</p>
<p>Customer status: {customerStatus}</p>
<button onClick={openWidget}>Open widget</button>
</div>
);
}

Modules