> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/plugins-and-integrations/convai-pixel-streaming-embed/react-typescript.md).

# React Typescript

Set up and integrate Convai's Pixel Streaming component in your React TypeScript app using @convai/experience-embed.

{% embed url="<https://www.npmjs.com/package/@convai/experience-embed>" %}

## Installation Instructions

To install `@convai/experience-embed` using your preferred package manager, use one of the following commands:

#### npm

```bash
npm install @convai/experience-embed
```

#### yarn

```bash
yarn add @convai/experience-embed
```

#### pnpm

```bash
pnpm add @convai
```

## Quick Start (React Ts)

### 1. Import the Component

```tsx
import { PixelStreamComponent } from '@convai/experience-embed';
```

***

### 2. Set Up a Ref to Access Methods

<pre class="language-tsx"><code class="lang-tsx"><strong>import { useRef } from 'react';
</strong>import { PixelStreamComponentHandles } from '@convai/experience-embed';

const pixelStreamRef = useRef&#x3C;PixelStreamComponentHandles>(null);
</code></pre>

### 3. Use the Component in JSX

```tsx
<PixelStreamComponent
  ref={pixelStreamRef}
  expId="your-experience-id"
  InitialScreen={<div>Loading your experience...</div>}
/>
```

{% hint style="info" %}
`expId` is your unique experience ID from Convai's dashboard.
{% endhint %}

### 4. Interact Using Available Methods

**Enable/Disable Camera**

```tsx
await pixelStreamRef.current?.enableCamera();
await pixelStreamRef.current?.disableCamera();
```

**Enable/Disable Character Audio**

```tsx
await pixelStreamRef.current?.enableCharacterAudio();
await pixelStreamRef.current?.disableCharacterAudio();
```

**Initialise the Experience**

```tsx
await pixelStreamRef.current?.initializeExperience();
```

### 5. Customise the Loading Screen (Optional)

```tsx
const CustomLoadingScreen = () => (
  <div style={{
    width: '100%',
    height: '100%',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    background: '#000',
    color: '#fff',
  }}>
    <h2>Loading your experience...</h2>
  </div>
);
```

Usage:

```tsx
<PixelStreamComponent
  ref={pixelStreamRef}
  expId="your-experience-id"
  InitialScreen={<CustomLoadingScreen />}
/>
```

## Full Example

```tsx
import React, { useRef } from 'react';
import {
  PixelStreamComponent,
  PixelStreamComponentHandles,
} from '@convai/experience-embed';

function App() {
  const pixelStreamRef = useRef<PixelStreamComponentHandles>(null);

  const handleEnableCamera = async () => {
    await pixelStreamRef.current?.enableCamera();
  };

  const handleDisableCamera = async () => {
    await pixelStreamRef.current?.disableCamera();
  };

  return (
    <div>
      <PixelStreamComponent
        ref={pixelStreamRef}
        expId="your-experience-id"
        InitialScreen={<div>Loading your experience...</div>}
      />
      <button onClick={handleEnableCamera}>Enable Camera</button>
      <button onClick={handleDisableCamera}>Disable Camera</button>
    </div>
  );
}

export default App;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.convai.com/api-docs/plugins-and-integrations/convai-pixel-streaming-embed/react-typescript.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
