> For the complete documentation index, see [llms.txt](https://docs.dotpassport.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dotpassport.io/framework-integration/react.md).

# React

Integrate DotPassport widgets into React applications.

## Installation

```bash
npm install @dotpassport/sdk
```

## Basic Component

Create a reusable widget component:

```tsx
import { useEffect, useRef } from 'react';
import { createWidget, type WidgetConfig } from '@dotpassport/sdk';

export function DotPassportWidget(config: WidgetConfig) {
  const ref = useRef<HTMLDivElement>(null);
  const widgetRef = useRef<any>();

  useEffect(() => {
    if (ref.current && !widgetRef.current) {
      widgetRef.current = createWidget(config);
      widgetRef.current.mount(ref.current);
    }
    return () => widgetRef.current?.destroy();
  }, []);

  useEffect(() => {
    widgetRef.current?.update(config);
  }, [config]);

  return <div ref={ref} />;
}
```

## Usage

```tsx
import { DotPassportWidget } from './components/DotPassportWidget';

function App() {
  return (
    <DotPassportWidget
      apiKey={process.env.REACT_APP_DOTPASSPORT_API_KEY!}
      address="5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
      type="reputation"
    />
  );
}
```

## Dynamic Updates

```tsx
import { useState } from 'react';
import { DotPassportWidget } from './components/DotPassportWidget';

function UserProfile({ address }: { address: string }) {
  const [theme, setTheme] = useState<'light' | 'dark'>('light');

  return (
    <div>
      <button onClick={() => setTheme(t => t === 'light' ? 'dark' : 'light')}>
        Toggle Theme
      </button>

      <DotPassportWidget
        apiKey={process.env.REACT_APP_DOTPASSPORT_API_KEY!}
        address={address}
        type="reputation"
        theme={theme}
      />
    </div>
  );
}
```

## Multiple Widgets

```tsx
function Dashboard({ address }: { address: string }) {
  return (
    <div className="grid grid-cols-2 gap-4">
      <DotPassportWidget
        apiKey={apiKey}
        address={address}
        type="reputation"
      />

      <DotPassportWidget
        apiKey={apiKey}
        address={address}
        type="badges"
      />

      <DotPassportWidget
        apiKey={apiKey}
        address={address}
        type="profile"
      />
    </div>
  );
}
```

## Next Steps

* [Vue Integration](https://github.com/dotpassport/dotpassport-sdk/blob/main/docs/frameworks/vue.md)
* [Widget Configuration](/widgets/overview.md)
* [Error Handling](https://github.com/dotpassport/dotpassport-sdk/blob/main/docs/api-client/error-handling.md)


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dotpassport.io/framework-integration/react.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
