---
title: Widget de documentación de la aplicación - React
slug: widget-de-documentacion-de-la-aplicacion-react
createdAt: 2023-11-17T14:25:39.130Z
---

Ya hemos explicado algunos de los [beneficios de la documentación contextual](docId\:z_lxm9QP9YF2452r-33tz) en el capítulo anterior. Esta guía sirve como una alternativa para `React` y `NextJS` para integrar el widget de la app Archbee de una manera más elegante.

## Integrar widget de la app

:::::WorkflowBlock
:::WorkflowBlockItem
Instala nuestro [paquete npm](https://www.npmjs.com/package/@archbee/app-widget):

```shell
# with npm
$ npm install --save @archbee/app-widget

# or with yarn
$ yarn add @archbee/app-widget
```
:::

::::WorkflowBlockItem
Cuando el paquete esté instalado, ve a tu archivo `jsx/tsx` e instancia el componente:

:::CodeblockTabs
React

```typescript
import React from 'react';
import { ArchbeeAppWidget, AbWidgetRef } from '@archbee/app-widget'

function App() {
const widgetRef = useRef<AbWidgetRef>(null);

  return (
    <div>
        <ArchbeeAppWidget
            ref={widgetRef}
            spaceId={ /** published space id **/ }
            onWidgetOpen={() => { /** ... **/ }} // callback function called after widget has open
            onWidgetClose={() => { /** ... **/ }} // callback function called after widget has open
      >
        <button type='button' onClick={() => {
        <!-- Opens widget -->
            widgetRef.current?.open();
        }}>
          Open
        </button>
        
        <button type='button' onClick={() => {
        <!-- Closes widget -->
            widgetRef.current?.close();
        }}>
          Close
        </button>
        
        <button type='button' onClick={() => {
        <!-- Gets the instance of the widget if needed for various event manipulations. -->
            widgetRef.current?.instance();
        }}>
          Get widget instance
        </button>
      </ArchbeeAppWidget>
    </div>
  );
}
```
:::
::::

:::WorkflowBlockItem
También puedes consultar la información desde **Configuración del Espacio**:

1. Selecciona tu **Espacio&#x20;**&#x64;entro del editor.
2. Haz clic en el ícono de engranaje (⚙️) para entrar a **Configuración.**
3. Ve a **Integración del Widget**.
4. Haz clic en la pestaña `React` y luego en el botón de copiar, y pega el código en tu archivo `tsx/.jsx`
:::
:::::

Ahora, el widget se encargará de todo detrás de escena. No te preocupes, todo está empaquetado y minimizado. Es una descarga de apenas 56Kb y se carga de forma asíncrona, por lo que tus usuarios no notarán la diferencia.

### Propiedades del componente

| **Property**        | **Type**             | **Required** | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ------------------- | -------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `spaceId`           | `string`             | `required`   | Pass the desired id to load your docs.                                                                                                                                                                                                                                                                                                                                                                                                            |
| `docId`             | `string`             | `optional`   | The doc where you want to open the widget docs. If `docId` is passed, `widgetType` is ignored, it will open in `docs` mode regardless of the prop passed.                                                                                                                                                                                                                                                                                         |
| `shareableToken`    | `string`             | `optional`   | Pass the shareableToken from your private links to protect your docs.                                                                                                                                                                                                                                                                                                                                                                             |
| `className`         | `string`             | `optional`   | Pass CSS classes to the `div` wrapper.                                                                                                                                                                                                                                                                                                                                                                                                            |
| `widgetType`        | `'docs' \| 'search'` | `optional`   | Default value is `docs`. This opens the widget with the desired behaviour. `docs` type will open the widget with the default behaviour, `search` will open a search widget bar that shows a search bar with AI support (if included in your subscription).                                                                                                                                                                                        |
| `hideNavbar`        | `boolean`            | `optional`   | It shows or hides the top navbar from the widget modal. By default the navbar is visible. If you don't want to see the navbar, pass it with `true` value, otherwise just skip it.                                                                                                                                                                                                                                                                 |
| `loadingStrategy`   | `'eager' \| 'lazy'`  | `optional`   | Default value is `lazy`. Loading strategy method for widget loading.                                                                                                                                                                                                                                                                                                                                                                              |
| `bubble`            | `invisible \| ask`   | `optional`   | The default value is `invisible`. If set to `ask`, it will display a bubble in the bottom-right of your screen. Whenever someone clicks on it, the search widget will open.                                                                                                                                                                                                                                                                       |
| `bubblePlaceholder` | `string`             | `optional`   | The placeholder that will be displayed in the bubble section. If not passed, a default value of `Ask a question` will be displayed.                                                                                                                                                                                                                                                                                                               |
| `anchor`            | `string`             | `optional`   | You can provide your `class`, `id` or `path` to a DOM element where you would like the widget to anchor and instantiate. It will anchor to the first element found in the DOM, if multiple elements with the same path are present. The container provided should have `position: relative` as the widget will be displayed based on the first **relative** **parent** found.<br />e.g.: `anchor: "#my-container"` / `anchor: ".container-class"` |
| `onWidgetOpen`      | `void`               | `optional`   | Callback that is called after the widget opens.                                                                                                                                                                                                                                                                                                                                                                                                   |
| `onWidgetClose`     | `void`               | `optional`   | Callback that is called after the widget closes.                                                                                                                                                                                                                                                                                                                                                                                                  |

:::hint{type="info"}
Los tokens compartibles están disponibles en el [plan Scaling](https://www.archbee.com/pricing). Lea más sobre [Controles de acceso público](docId\:Ok0ZudAh9RZS3_baFhfQv).
:::

### Métodos Ref

:::hint{type="info"}
Si `ref` no se pasa a `ArchbeeAppWidget`, los hijos abrirán automáticamente la ventana emergente modal al hacer clic.
:::

| **Propiedad** | **Tipo** | **Descripción**                         |
| ------------- | -------- | --------------------------------------- |
| `abrir`       | `método` | Abre el widget mediante programación.   |
| `cerrar`      | `método` | Cierra el widget mediante programación. |
| `instancia`   | `método` | Devuelve la instancia del widget.       |

